2 * Copyright 2018 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>
27 #include "amdgpu_discovery.h"
28 #include "soc15_hw_ip.h"
29 #include "discovery.h"
30 #include "amdgpu_ras.h"
34 #include "gfx_v9_4_3.h"
39 #include "df_v4_6_2.h"
40 #include "nbio_v6_1.h"
41 #include "nbio_v7_0.h"
42 #include "nbio_v7_4.h"
43 #include "nbio_v7_9.h"
44 #include "nbio_v7_11.h"
46 #include "vega10_ih.h"
47 #include "vega20_ih.h"
48 #include "sdma_v4_0.h"
49 #include "sdma_v4_4_2.h"
54 #include "jpeg_v2_5.h"
55 #include "smuio_v9_0.h"
56 #include "gmc_v10_0.h"
57 #include "gmc_v11_0.h"
58 #include "gmc_v12_0.h"
59 #include "gfxhub_v2_0.h"
60 #include "mmhub_v2_0.h"
61 #include "nbio_v2_3.h"
62 #include "nbio_v4_3.h"
63 #include "nbio_v7_2.h"
64 #include "nbio_v7_7.h"
65 #include "nbif_v6_3_1.h"
73 #include "navi10_ih.h"
77 #include "gfx_v10_0.h"
78 #include "gfx_v11_0.h"
79 #include "gfx_v12_0.h"
80 #include "sdma_v5_0.h"
81 #include "sdma_v5_2.h"
82 #include "sdma_v6_0.h"
83 #include "sdma_v7_0.h"
84 #include "lsdma_v6_0.h"
85 #include "lsdma_v7_0.h"
87 #include "jpeg_v2_0.h"
89 #include "jpeg_v3_0.h"
91 #include "jpeg_v4_0.h"
92 #include "vcn_v4_0_3.h"
93 #include "jpeg_v4_0_3.h"
94 #include "vcn_v4_0_5.h"
95 #include "jpeg_v4_0_5.h"
96 #include "amdgpu_vkms.h"
97 #include "mes_v11_0.h"
98 #include "mes_v12_0.h"
99 #include "smuio_v11_0.h"
100 #include "smuio_v11_0_6.h"
101 #include "smuio_v13_0.h"
102 #include "smuio_v13_0_3.h"
103 #include "smuio_v13_0_6.h"
104 #include "smuio_v14_0_2.h"
105 #include "vcn_v5_0_0.h"
106 #include "jpeg_v5_0_0.h"
108 #include "amdgpu_vpe.h"
109 #if defined(CONFIG_DRM_AMD_ISP)
110 #include "amdgpu_isp.h"
113 #define FIRMWARE_IP_DISCOVERY "amdgpu/ip_discovery.bin"
114 MODULE_FIRMWARE(FIRMWARE_IP_DISCOVERY);
116 #define mmIP_DISCOVERY_VERSION 0x16A00
117 #define mmRCC_CONFIG_MEMSIZE 0xde3
118 #define mmMP0_SMN_C2PMSG_33 0x16061
119 #define mmMM_INDEX 0x0
120 #define mmMM_INDEX_HI 0x6
121 #define mmMM_DATA 0x1
123 static const char *hw_id_names[HW_ID_MAX] = {
127 [SMUIO_HWID] = "SMUIO",
128 [FUSE_HWID] = "FUSE",
129 [CLKA_HWID] = "CLKA",
133 [AUDIO_AZ_HWID] = "AUDIO_AZ",
139 [XDMA_HWID] = "XDMA",
140 [DCEAZ_HWID] = "DCEAZ",
142 [SDPMUX_HWID] = "SDPMUX",
144 [IOHC_HWID] = "IOHC",
145 [L2IMU_HWID] = "L2IMU",
147 [MMHUB_HWID] = "MMHUB",
148 [ATHUB_HWID] = "ATHUB",
149 [DBGU_NBIO_HWID] = "DBGU_NBIO",
151 [DBGU0_HWID] = "DBGU0",
152 [DBGU1_HWID] = "DBGU1",
153 [OSSSYS_HWID] = "OSSSYS",
155 [SDMA0_HWID] = "SDMA0",
156 [SDMA1_HWID] = "SDMA1",
157 [SDMA2_HWID] = "SDMA2",
158 [SDMA3_HWID] = "SDMA3",
159 [LSDMA_HWID] = "LSDMA",
161 [DBGU_IO_HWID] = "DBGU_IO",
163 [CLKB_HWID] = "CLKB",
165 [DFX_DAP_HWID] = "DFX_DAP",
166 [L1IMU_PCIE_HWID] = "L1IMU_PCIE",
167 [L1IMU_NBIF_HWID] = "L1IMU_NBIF",
168 [L1IMU_IOAGR_HWID] = "L1IMU_IOAGR",
169 [L1IMU3_HWID] = "L1IMU3",
170 [L1IMU4_HWID] = "L1IMU4",
171 [L1IMU5_HWID] = "L1IMU5",
172 [L1IMU6_HWID] = "L1IMU6",
173 [L1IMU7_HWID] = "L1IMU7",
174 [L1IMU8_HWID] = "L1IMU8",
175 [L1IMU9_HWID] = "L1IMU9",
176 [L1IMU10_HWID] = "L1IMU10",
177 [L1IMU11_HWID] = "L1IMU11",
178 [L1IMU12_HWID] = "L1IMU12",
179 [L1IMU13_HWID] = "L1IMU13",
180 [L1IMU14_HWID] = "L1IMU14",
181 [L1IMU15_HWID] = "L1IMU15",
182 [WAFLC_HWID] = "WAFLC",
183 [FCH_USB_PD_HWID] = "FCH_USB_PD",
184 [PCIE_HWID] = "PCIE",
186 [DDCL_HWID] = "DDCL",
188 [IOAGR_HWID] = "IOAGR",
189 [NBIF_HWID] = "NBIF",
190 [IOAPIC_HWID] = "IOAPIC",
191 [SYSTEMHUB_HWID] = "SYSTEMHUB",
192 [NTBCCP_HWID] = "NTBCCP",
194 [SATA_HWID] = "SATA",
196 [CCXSEC_HWID] = "CCXSEC",
197 [XGMI_HWID] = "XGMI",
198 [XGBE_HWID] = "XGBE",
203 static int hw_id_map[MAX_HWIP] = {
205 [HDP_HWIP] = HDP_HWID,
206 [SDMA0_HWIP] = SDMA0_HWID,
207 [SDMA1_HWIP] = SDMA1_HWID,
208 [SDMA2_HWIP] = SDMA2_HWID,
209 [SDMA3_HWIP] = SDMA3_HWID,
210 [LSDMA_HWIP] = LSDMA_HWID,
211 [MMHUB_HWIP] = MMHUB_HWID,
212 [ATHUB_HWIP] = ATHUB_HWID,
213 [NBIO_HWIP] = NBIF_HWID,
214 [MP0_HWIP] = MP0_HWID,
215 [MP1_HWIP] = MP1_HWID,
216 [UVD_HWIP] = UVD_HWID,
217 [VCE_HWIP] = VCE_HWID,
219 [DCE_HWIP] = DMU_HWID,
220 [OSSSYS_HWIP] = OSSSYS_HWID,
221 [SMUIO_HWIP] = SMUIO_HWID,
222 [PWR_HWIP] = PWR_HWID,
223 [NBIF_HWIP] = NBIF_HWID,
224 [THM_HWIP] = THM_HWID,
225 [CLK_HWIP] = CLKA_HWID,
226 [UMC_HWIP] = UMC_HWID,
227 [XGMI_HWIP] = XGMI_HWID,
228 [DCI_HWIP] = DCI_HWID,
229 [PCIE_HWIP] = PCIE_HWID,
230 [VPE_HWIP] = VPE_HWID,
231 [ISP_HWIP] = ISP_HWID,
234 static int amdgpu_discovery_read_binary_from_sysmem(struct amdgpu_device *adev, uint8_t *binary)
236 u64 tmr_offset, tmr_size, pos;
240 ret = amdgpu_acpi_get_tmr_info(adev, &tmr_offset, &tmr_size);
244 pos = tmr_offset + tmr_size - DISCOVERY_TMR_OFFSET;
246 /* This region is read-only and reserved from system use */
247 discv_regn = memremap(pos, adev->mman.discovery_tmr_size, MEMREMAP_WC);
249 memcpy(binary, discv_regn, adev->mman.discovery_tmr_size);
250 memunmap(discv_regn);
257 #define IP_DISCOVERY_V2 2
258 #define IP_DISCOVERY_V4 4
260 static int amdgpu_discovery_read_binary_from_mem(struct amdgpu_device *adev,
267 if (!amdgpu_sriov_vf(adev)) {
268 /* It can take up to a second for IFWI init to complete on some dGPUs,
269 * but generally it should be in the 60-100ms range. Normally this starts
270 * as soon as the device gets power so by the time the OS loads this has long
271 * completed. However, when a card is hotplugged via e.g., USB4, we need to
272 * wait for this to complete. Once the C2PMSG is updated, we can
276 for (i = 0; i < 1000; i++) {
277 msg = RREG32(mmMP0_SMN_C2PMSG_33);
278 if (msg & 0x80000000)
280 usleep_range(1000, 1100);
284 vram_size = (uint64_t)RREG32(mmRCC_CONFIG_MEMSIZE) << 20;
287 uint64_t pos = vram_size - DISCOVERY_TMR_OFFSET;
288 amdgpu_device_vram_access(adev, pos, (uint32_t *)binary,
289 adev->mman.discovery_tmr_size, false);
291 ret = amdgpu_discovery_read_binary_from_sysmem(adev, binary);
297 static int amdgpu_discovery_read_binary_from_file(struct amdgpu_device *adev, uint8_t *binary)
299 const struct firmware *fw;
303 switch (amdgpu_discovery) {
305 fw_name = FIRMWARE_IP_DISCOVERY;
308 dev_warn(adev->dev, "amdgpu_discovery is not set properly\n");
312 r = request_firmware(&fw, fw_name, adev->dev);
314 dev_err(adev->dev, "can't load firmware \"%s\"\n",
319 memcpy((u8 *)binary, (u8 *)fw->data, fw->size);
320 release_firmware(fw);
325 static uint16_t amdgpu_discovery_calculate_checksum(uint8_t *data, uint32_t size)
327 uint16_t checksum = 0;
330 for (i = 0; i < size; i++)
336 static inline bool amdgpu_discovery_verify_checksum(uint8_t *data, uint32_t size,
339 return !!(amdgpu_discovery_calculate_checksum(data, size) == expected);
342 static inline bool amdgpu_discovery_verify_binary_signature(uint8_t *binary)
344 struct binary_header *bhdr;
345 bhdr = (struct binary_header *)binary;
347 return (le32_to_cpu(bhdr->binary_signature) == BINARY_SIGNATURE);
350 static void amdgpu_discovery_harvest_config_quirk(struct amdgpu_device *adev)
353 * So far, apply this quirk only on those Navy Flounder boards which
354 * have a bad harvest table of VCN config.
356 if ((amdgpu_ip_version(adev, UVD_HWIP, 1) == IP_VERSION(3, 0, 1)) &&
357 (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(10, 3, 2))) {
358 switch (adev->pdev->revision) {
366 adev->vcn.harvest_config |= AMDGPU_VCN_HARVEST_VCN1;
367 adev->vcn.inst_mask &= ~AMDGPU_VCN_HARVEST_VCN1;
375 static int amdgpu_discovery_verify_npsinfo(struct amdgpu_device *adev,
376 struct binary_header *bhdr)
378 struct table_info *info;
382 info = &bhdr->table_list[NPS_INFO];
383 offset = le16_to_cpu(info->offset);
384 checksum = le16_to_cpu(info->checksum);
386 struct nps_info_header *nhdr =
387 (struct nps_info_header *)(adev->mman.discovery_bin + offset);
389 if (le32_to_cpu(nhdr->table_id) != NPS_INFO_TABLE_ID) {
390 dev_dbg(adev->dev, "invalid ip discovery nps info table id\n");
394 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset,
395 le32_to_cpu(nhdr->size_bytes),
397 dev_dbg(adev->dev, "invalid nps info data table checksum\n");
404 static int amdgpu_discovery_init(struct amdgpu_device *adev)
406 struct table_info *info;
407 struct binary_header *bhdr;
413 adev->mman.discovery_tmr_size = DISCOVERY_TMR_SIZE;
414 adev->mman.discovery_bin = kzalloc(adev->mman.discovery_tmr_size, GFP_KERNEL);
415 if (!adev->mman.discovery_bin)
418 /* Read from file if it is the preferred option */
419 if (amdgpu_discovery == 2) {
420 dev_info(adev->dev, "use ip discovery information from file");
421 r = amdgpu_discovery_read_binary_from_file(adev, adev->mman.discovery_bin);
424 dev_err(adev->dev, "failed to read ip discovery binary from file\n");
430 r = amdgpu_discovery_read_binary_from_mem(
431 adev, adev->mman.discovery_bin);
436 /* check the ip discovery binary signature */
437 if (!amdgpu_discovery_verify_binary_signature(adev->mman.discovery_bin)) {
439 "get invalid ip discovery binary signature\n");
444 bhdr = (struct binary_header *)adev->mman.discovery_bin;
446 offset = offsetof(struct binary_header, binary_checksum) +
447 sizeof(bhdr->binary_checksum);
448 size = le16_to_cpu(bhdr->binary_size) - offset;
449 checksum = le16_to_cpu(bhdr->binary_checksum);
451 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset,
453 dev_err(adev->dev, "invalid ip discovery binary checksum\n");
458 info = &bhdr->table_list[IP_DISCOVERY];
459 offset = le16_to_cpu(info->offset);
460 checksum = le16_to_cpu(info->checksum);
463 struct ip_discovery_header *ihdr =
464 (struct ip_discovery_header *)(adev->mman.discovery_bin + offset);
465 if (le32_to_cpu(ihdr->signature) != DISCOVERY_TABLE_SIGNATURE) {
466 dev_err(adev->dev, "invalid ip discovery data table signature\n");
471 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset,
472 le16_to_cpu(ihdr->size), checksum)) {
473 dev_err(adev->dev, "invalid ip discovery data table checksum\n");
479 info = &bhdr->table_list[GC];
480 offset = le16_to_cpu(info->offset);
481 checksum = le16_to_cpu(info->checksum);
484 struct gpu_info_header *ghdr =
485 (struct gpu_info_header *)(adev->mman.discovery_bin + offset);
487 if (le32_to_cpu(ghdr->table_id) != GC_TABLE_ID) {
488 dev_err(adev->dev, "invalid ip discovery gc table id\n");
493 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset,
494 le32_to_cpu(ghdr->size), checksum)) {
495 dev_err(adev->dev, "invalid gc data table checksum\n");
501 info = &bhdr->table_list[HARVEST_INFO];
502 offset = le16_to_cpu(info->offset);
503 checksum = le16_to_cpu(info->checksum);
506 struct harvest_info_header *hhdr =
507 (struct harvest_info_header *)(adev->mman.discovery_bin + offset);
509 if (le32_to_cpu(hhdr->signature) != HARVEST_TABLE_SIGNATURE) {
510 dev_err(adev->dev, "invalid ip discovery harvest table signature\n");
515 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset,
516 sizeof(struct harvest_table), checksum)) {
517 dev_err(adev->dev, "invalid harvest data table checksum\n");
523 info = &bhdr->table_list[VCN_INFO];
524 offset = le16_to_cpu(info->offset);
525 checksum = le16_to_cpu(info->checksum);
528 struct vcn_info_header *vhdr =
529 (struct vcn_info_header *)(adev->mman.discovery_bin + offset);
531 if (le32_to_cpu(vhdr->table_id) != VCN_INFO_TABLE_ID) {
532 dev_err(adev->dev, "invalid ip discovery vcn table id\n");
537 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset,
538 le32_to_cpu(vhdr->size_bytes), checksum)) {
539 dev_err(adev->dev, "invalid vcn data table checksum\n");
545 info = &bhdr->table_list[MALL_INFO];
546 offset = le16_to_cpu(info->offset);
547 checksum = le16_to_cpu(info->checksum);
550 struct mall_info_header *mhdr =
551 (struct mall_info_header *)(adev->mman.discovery_bin + offset);
553 if (le32_to_cpu(mhdr->table_id) != MALL_INFO_TABLE_ID) {
554 dev_err(adev->dev, "invalid ip discovery mall table id\n");
559 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset,
560 le32_to_cpu(mhdr->size_bytes), checksum)) {
561 dev_err(adev->dev, "invalid mall data table checksum\n");
570 kfree(adev->mman.discovery_bin);
571 adev->mman.discovery_bin = NULL;
572 if ((amdgpu_discovery != 2) &&
573 (RREG32(mmIP_DISCOVERY_VERSION) == 4))
574 amdgpu_ras_query_boot_status(adev, 4);
578 static void amdgpu_discovery_sysfs_fini(struct amdgpu_device *adev);
580 void amdgpu_discovery_fini(struct amdgpu_device *adev)
582 amdgpu_discovery_sysfs_fini(adev);
583 kfree(adev->mman.discovery_bin);
584 adev->mman.discovery_bin = NULL;
587 static int amdgpu_discovery_validate_ip(const struct ip_v4 *ip)
589 if (ip->instance_number >= HWIP_MAX_INSTANCE) {
590 DRM_ERROR("Unexpected instance_number (%d) from ip discovery blob\n",
591 ip->instance_number);
594 if (le16_to_cpu(ip->hw_id) >= HW_ID_MAX) {
595 DRM_ERROR("Unexpected hw_id (%d) from ip discovery blob\n",
596 le16_to_cpu(ip->hw_id));
603 static void amdgpu_discovery_read_harvest_bit_per_ip(struct amdgpu_device *adev,
604 uint32_t *vcn_harvest_count)
606 struct binary_header *bhdr;
607 struct ip_discovery_header *ihdr;
608 struct die_header *dhdr;
610 uint16_t die_offset, ip_offset, num_dies, num_ips;
613 bhdr = (struct binary_header *)adev->mman.discovery_bin;
614 ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin +
615 le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset));
616 num_dies = le16_to_cpu(ihdr->num_dies);
618 /* scan harvest bit of all IP data structures */
619 for (i = 0; i < num_dies; i++) {
620 die_offset = le16_to_cpu(ihdr->die_info[i].die_offset);
621 dhdr = (struct die_header *)(adev->mman.discovery_bin + die_offset);
622 num_ips = le16_to_cpu(dhdr->num_ips);
623 ip_offset = die_offset + sizeof(*dhdr);
625 for (j = 0; j < num_ips; j++) {
626 ip = (struct ip_v4 *)(adev->mman.discovery_bin + ip_offset);
628 if (amdgpu_discovery_validate_ip(ip))
631 if (le16_to_cpu(ip->variant) == 1) {
632 switch (le16_to_cpu(ip->hw_id)) {
634 (*vcn_harvest_count)++;
635 if (ip->instance_number == 0) {
636 adev->vcn.harvest_config |= AMDGPU_VCN_HARVEST_VCN0;
637 adev->vcn.inst_mask &=
638 ~AMDGPU_VCN_HARVEST_VCN0;
639 adev->jpeg.inst_mask &=
640 ~AMDGPU_VCN_HARVEST_VCN0;
642 adev->vcn.harvest_config |= AMDGPU_VCN_HARVEST_VCN1;
643 adev->vcn.inst_mask &=
644 ~AMDGPU_VCN_HARVEST_VCN1;
645 adev->jpeg.inst_mask &=
646 ~AMDGPU_VCN_HARVEST_VCN1;
650 adev->harvest_ip_mask |= AMD_HARVEST_IP_DMU_MASK;
657 if (ihdr->base_addr_64_bit)
658 ip_offset += struct_size(ip, base_address_64, ip->num_base_address);
660 ip_offset += struct_size(ip, base_address, ip->num_base_address);
665 static void amdgpu_discovery_read_from_harvest_table(struct amdgpu_device *adev,
666 uint32_t *vcn_harvest_count,
667 uint32_t *umc_harvest_count)
669 struct binary_header *bhdr;
670 struct harvest_table *harvest_info;
673 uint32_t umc_harvest_config = 0;
675 bhdr = (struct binary_header *)adev->mman.discovery_bin;
676 offset = le16_to_cpu(bhdr->table_list[HARVEST_INFO].offset);
679 dev_err(adev->dev, "invalid harvest table offset\n");
683 harvest_info = (struct harvest_table *)(adev->mman.discovery_bin + offset);
685 for (i = 0; i < 32; i++) {
686 if (le16_to_cpu(harvest_info->list[i].hw_id) == 0)
689 switch (le16_to_cpu(harvest_info->list[i].hw_id)) {
691 (*vcn_harvest_count)++;
692 adev->vcn.harvest_config |=
693 (1 << harvest_info->list[i].number_instance);
694 adev->jpeg.harvest_config |=
695 (1 << harvest_info->list[i].number_instance);
697 adev->vcn.inst_mask &=
698 ~(1U << harvest_info->list[i].number_instance);
699 adev->jpeg.inst_mask &=
700 ~(1U << harvest_info->list[i].number_instance);
703 adev->harvest_ip_mask |= AMD_HARVEST_IP_DMU_MASK;
706 umc_harvest_config |=
707 1 << (le16_to_cpu(harvest_info->list[i].number_instance));
708 (*umc_harvest_count)++;
711 adev->gfx.xcc_mask &=
712 ~(1U << harvest_info->list[i].number_instance);
715 adev->sdma.sdma_mask &=
716 ~(1U << harvest_info->list[i].number_instance);
718 #if defined(CONFIG_DRM_AMD_ISP)
720 adev->isp.harvest_config |=
721 ~(1U << harvest_info->list[i].number_instance);
729 adev->umc.active_mask = ((1 << adev->umc.node_inst_num) - 1) &
733 /* ================================================== */
735 struct ip_hw_instance {
736 struct kobject kobj; /* ip_discovery/die/#die/#hw_id/#instance/<attrs...> */
740 u8 major, minor, revision;
743 int num_base_addresses;
744 u32 base_addr[] __counted_by(num_base_addresses);
748 struct kset hw_id_kset; /* ip_discovery/die/#die/#hw_id/, contains ip_hw_instance */
752 struct ip_die_entry {
753 struct kset ip_kset; /* ip_discovery/die/#die/, contains ip_hw_id */
757 /* -------------------------------------------------- */
759 struct ip_hw_instance_attr {
760 struct attribute attr;
761 ssize_t (*show)(struct ip_hw_instance *ip_hw_instance, char *buf);
764 static ssize_t hw_id_show(struct ip_hw_instance *ip_hw_instance, char *buf)
766 return sysfs_emit(buf, "%d\n", ip_hw_instance->hw_id);
769 static ssize_t num_instance_show(struct ip_hw_instance *ip_hw_instance, char *buf)
771 return sysfs_emit(buf, "%d\n", ip_hw_instance->num_instance);
774 static ssize_t major_show(struct ip_hw_instance *ip_hw_instance, char *buf)
776 return sysfs_emit(buf, "%d\n", ip_hw_instance->major);
779 static ssize_t minor_show(struct ip_hw_instance *ip_hw_instance, char *buf)
781 return sysfs_emit(buf, "%d\n", ip_hw_instance->minor);
784 static ssize_t revision_show(struct ip_hw_instance *ip_hw_instance, char *buf)
786 return sysfs_emit(buf, "%d\n", ip_hw_instance->revision);
789 static ssize_t harvest_show(struct ip_hw_instance *ip_hw_instance, char *buf)
791 return sysfs_emit(buf, "0x%01X\n", ip_hw_instance->harvest);
794 static ssize_t num_base_addresses_show(struct ip_hw_instance *ip_hw_instance, char *buf)
796 return sysfs_emit(buf, "%d\n", ip_hw_instance->num_base_addresses);
799 static ssize_t base_addr_show(struct ip_hw_instance *ip_hw_instance, char *buf)
804 for (res = at = ii = 0; ii < ip_hw_instance->num_base_addresses; ii++) {
805 /* Here we satisfy the condition that, at + size <= PAGE_SIZE.
807 if (at + 12 > PAGE_SIZE)
809 res = sysfs_emit_at(buf, at, "0x%08X\n",
810 ip_hw_instance->base_addr[ii]);
816 return res < 0 ? res : at;
819 static struct ip_hw_instance_attr ip_hw_attr[] = {
821 __ATTR_RO(num_instance),
826 __ATTR_RO(num_base_addresses),
827 __ATTR_RO(base_addr),
830 static struct attribute *ip_hw_instance_attrs[ARRAY_SIZE(ip_hw_attr) + 1];
831 ATTRIBUTE_GROUPS(ip_hw_instance);
833 #define to_ip_hw_instance(x) container_of(x, struct ip_hw_instance, kobj)
834 #define to_ip_hw_instance_attr(x) container_of(x, struct ip_hw_instance_attr, attr)
836 static ssize_t ip_hw_instance_attr_show(struct kobject *kobj,
837 struct attribute *attr,
840 struct ip_hw_instance *ip_hw_instance = to_ip_hw_instance(kobj);
841 struct ip_hw_instance_attr *ip_hw_attr = to_ip_hw_instance_attr(attr);
843 if (!ip_hw_attr->show)
846 return ip_hw_attr->show(ip_hw_instance, buf);
849 static const struct sysfs_ops ip_hw_instance_sysfs_ops = {
850 .show = ip_hw_instance_attr_show,
853 static void ip_hw_instance_release(struct kobject *kobj)
855 struct ip_hw_instance *ip_hw_instance = to_ip_hw_instance(kobj);
857 kfree(ip_hw_instance);
860 static const struct kobj_type ip_hw_instance_ktype = {
861 .release = ip_hw_instance_release,
862 .sysfs_ops = &ip_hw_instance_sysfs_ops,
863 .default_groups = ip_hw_instance_groups,
866 /* -------------------------------------------------- */
868 #define to_ip_hw_id(x) container_of(to_kset(x), struct ip_hw_id, hw_id_kset)
870 static void ip_hw_id_release(struct kobject *kobj)
872 struct ip_hw_id *ip_hw_id = to_ip_hw_id(kobj);
874 if (!list_empty(&ip_hw_id->hw_id_kset.list))
875 DRM_ERROR("ip_hw_id->hw_id_kset is not empty");
879 static const struct kobj_type ip_hw_id_ktype = {
880 .release = ip_hw_id_release,
881 .sysfs_ops = &kobj_sysfs_ops,
884 /* -------------------------------------------------- */
886 static void die_kobj_release(struct kobject *kobj);
887 static void ip_disc_release(struct kobject *kobj);
889 struct ip_die_entry_attribute {
890 struct attribute attr;
891 ssize_t (*show)(struct ip_die_entry *ip_die_entry, char *buf);
894 #define to_ip_die_entry_attr(x) container_of(x, struct ip_die_entry_attribute, attr)
896 static ssize_t num_ips_show(struct ip_die_entry *ip_die_entry, char *buf)
898 return sysfs_emit(buf, "%d\n", ip_die_entry->num_ips);
901 /* If there are more ip_die_entry attrs, other than the number of IPs,
902 * we can make this intro an array of attrs, and then initialize
903 * ip_die_entry_attrs in a loop.
905 static struct ip_die_entry_attribute num_ips_attr =
908 static struct attribute *ip_die_entry_attrs[] = {
912 ATTRIBUTE_GROUPS(ip_die_entry); /* ip_die_entry_groups */
914 #define to_ip_die_entry(x) container_of(to_kset(x), struct ip_die_entry, ip_kset)
916 static ssize_t ip_die_entry_attr_show(struct kobject *kobj,
917 struct attribute *attr,
920 struct ip_die_entry_attribute *ip_die_entry_attr = to_ip_die_entry_attr(attr);
921 struct ip_die_entry *ip_die_entry = to_ip_die_entry(kobj);
923 if (!ip_die_entry_attr->show)
926 return ip_die_entry_attr->show(ip_die_entry, buf);
929 static void ip_die_entry_release(struct kobject *kobj)
931 struct ip_die_entry *ip_die_entry = to_ip_die_entry(kobj);
933 if (!list_empty(&ip_die_entry->ip_kset.list))
934 DRM_ERROR("ip_die_entry->ip_kset is not empty");
938 static const struct sysfs_ops ip_die_entry_sysfs_ops = {
939 .show = ip_die_entry_attr_show,
942 static const struct kobj_type ip_die_entry_ktype = {
943 .release = ip_die_entry_release,
944 .sysfs_ops = &ip_die_entry_sysfs_ops,
945 .default_groups = ip_die_entry_groups,
948 static const struct kobj_type die_kobj_ktype = {
949 .release = die_kobj_release,
950 .sysfs_ops = &kobj_sysfs_ops,
953 static const struct kobj_type ip_discovery_ktype = {
954 .release = ip_disc_release,
955 .sysfs_ops = &kobj_sysfs_ops,
958 struct ip_discovery_top {
959 struct kobject kobj; /* ip_discovery/ */
960 struct kset die_kset; /* ip_discovery/die/, contains ip_die_entry */
961 struct amdgpu_device *adev;
964 static void die_kobj_release(struct kobject *kobj)
966 struct ip_discovery_top *ip_top = container_of(to_kset(kobj),
967 struct ip_discovery_top,
969 if (!list_empty(&ip_top->die_kset.list))
970 DRM_ERROR("ip_top->die_kset is not empty");
973 static void ip_disc_release(struct kobject *kobj)
975 struct ip_discovery_top *ip_top = container_of(kobj, struct ip_discovery_top,
977 struct amdgpu_device *adev = ip_top->adev;
983 static uint8_t amdgpu_discovery_get_harvest_info(struct amdgpu_device *adev,
984 uint16_t hw_id, uint8_t inst)
988 /* Until a uniform way is figured, get mask based on hwid */
991 harvest = ((1 << inst) & adev->vcn.inst_mask) == 0;
994 if (adev->harvest_ip_mask & AMD_HARVEST_IP_DMU_MASK)
998 /* TODO: It needs another parsing; for now, ignore.*/
1001 harvest = ((1 << inst) & adev->gfx.xcc_mask) == 0;
1004 harvest = ((1 << inst) & adev->sdma.sdma_mask) == 0;
1013 static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev,
1014 struct ip_die_entry *ip_die_entry,
1015 const size_t _ip_offset, const int num_ips,
1018 int ii, jj, kk, res;
1020 DRM_DEBUG("num_ips:%d", num_ips);
1022 /* Find all IPs of a given HW ID, and add their instance to
1023 * #die/#hw_id/#instance/<attributes>
1025 for (ii = 0; ii < HW_ID_MAX; ii++) {
1026 struct ip_hw_id *ip_hw_id = NULL;
1027 size_t ip_offset = _ip_offset;
1029 for (jj = 0; jj < num_ips; jj++) {
1031 struct ip_hw_instance *ip_hw_instance;
1033 ip = (struct ip_v4 *)(adev->mman.discovery_bin + ip_offset);
1034 if (amdgpu_discovery_validate_ip(ip) ||
1035 le16_to_cpu(ip->hw_id) != ii)
1038 DRM_DEBUG("match:%d @ ip_offset:%zu", ii, ip_offset);
1040 /* We have a hw_id match; register the hw
1041 * block if not yet registered.
1044 ip_hw_id = kzalloc(sizeof(*ip_hw_id), GFP_KERNEL);
1047 ip_hw_id->hw_id = ii;
1049 kobject_set_name(&ip_hw_id->hw_id_kset.kobj, "%d", ii);
1050 ip_hw_id->hw_id_kset.kobj.kset = &ip_die_entry->ip_kset;
1051 ip_hw_id->hw_id_kset.kobj.ktype = &ip_hw_id_ktype;
1052 res = kset_register(&ip_hw_id->hw_id_kset);
1054 DRM_ERROR("Couldn't register ip_hw_id kset");
1058 if (hw_id_names[ii]) {
1059 res = sysfs_create_link(&ip_die_entry->ip_kset.kobj,
1060 &ip_hw_id->hw_id_kset.kobj,
1063 DRM_ERROR("Couldn't create IP link %s in IP Die:%s\n",
1065 kobject_name(&ip_die_entry->ip_kset.kobj));
1070 /* Now register its instance.
1072 ip_hw_instance = kzalloc(struct_size(ip_hw_instance,
1074 ip->num_base_address),
1076 if (!ip_hw_instance) {
1077 DRM_ERROR("no memory for ip_hw_instance");
1080 ip_hw_instance->hw_id = le16_to_cpu(ip->hw_id); /* == ii */
1081 ip_hw_instance->num_instance = ip->instance_number;
1082 ip_hw_instance->major = ip->major;
1083 ip_hw_instance->minor = ip->minor;
1084 ip_hw_instance->revision = ip->revision;
1085 ip_hw_instance->harvest =
1086 amdgpu_discovery_get_harvest_info(
1087 adev, ip_hw_instance->hw_id,
1088 ip_hw_instance->num_instance);
1089 ip_hw_instance->num_base_addresses = ip->num_base_address;
1091 for (kk = 0; kk < ip_hw_instance->num_base_addresses; kk++) {
1093 ip_hw_instance->base_addr[kk] =
1094 lower_32_bits(le64_to_cpu(ip->base_address_64[kk])) & 0x3FFFFFFF;
1096 ip_hw_instance->base_addr[kk] = ip->base_address[kk];
1099 kobject_init(&ip_hw_instance->kobj, &ip_hw_instance_ktype);
1100 ip_hw_instance->kobj.kset = &ip_hw_id->hw_id_kset;
1101 res = kobject_add(&ip_hw_instance->kobj, NULL,
1102 "%d", ip_hw_instance->num_instance);
1105 ip_offset += struct_size(ip, base_address_64,
1106 ip->num_base_address);
1108 ip_offset += struct_size(ip, base_address,
1109 ip->num_base_address);
1116 static int amdgpu_discovery_sysfs_recurse(struct amdgpu_device *adev)
1118 struct binary_header *bhdr;
1119 struct ip_discovery_header *ihdr;
1120 struct die_header *dhdr;
1121 struct kset *die_kset = &adev->ip_top->die_kset;
1122 u16 num_dies, die_offset, num_ips;
1126 bhdr = (struct binary_header *)adev->mman.discovery_bin;
1127 ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin +
1128 le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset));
1129 num_dies = le16_to_cpu(ihdr->num_dies);
1131 DRM_DEBUG("number of dies: %d\n", num_dies);
1133 for (ii = 0; ii < num_dies; ii++) {
1134 struct ip_die_entry *ip_die_entry;
1136 die_offset = le16_to_cpu(ihdr->die_info[ii].die_offset);
1137 dhdr = (struct die_header *)(adev->mman.discovery_bin + die_offset);
1138 num_ips = le16_to_cpu(dhdr->num_ips);
1139 ip_offset = die_offset + sizeof(*dhdr);
1141 /* Add the die to the kset.
1143 * dhdr->die_id == ii, which was checked in
1144 * amdgpu_discovery_reg_base_init().
1147 ip_die_entry = kzalloc(sizeof(*ip_die_entry), GFP_KERNEL);
1151 ip_die_entry->num_ips = num_ips;
1153 kobject_set_name(&ip_die_entry->ip_kset.kobj, "%d", le16_to_cpu(dhdr->die_id));
1154 ip_die_entry->ip_kset.kobj.kset = die_kset;
1155 ip_die_entry->ip_kset.kobj.ktype = &ip_die_entry_ktype;
1156 res = kset_register(&ip_die_entry->ip_kset);
1158 DRM_ERROR("Couldn't register ip_die_entry kset");
1159 kfree(ip_die_entry);
1163 amdgpu_discovery_sysfs_ips(adev, ip_die_entry, ip_offset, num_ips, !!ihdr->base_addr_64_bit);
1169 static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev)
1171 struct kset *die_kset;
1174 if (!adev->mman.discovery_bin)
1177 adev->ip_top = kzalloc(sizeof(*adev->ip_top), GFP_KERNEL);
1181 adev->ip_top->adev = adev;
1183 res = kobject_init_and_add(&adev->ip_top->kobj, &ip_discovery_ktype,
1184 &adev->dev->kobj, "ip_discovery");
1186 DRM_ERROR("Couldn't init and add ip_discovery/");
1190 die_kset = &adev->ip_top->die_kset;
1191 kobject_set_name(&die_kset->kobj, "%s", "die");
1192 die_kset->kobj.parent = &adev->ip_top->kobj;
1193 die_kset->kobj.ktype = &die_kobj_ktype;
1194 res = kset_register(&adev->ip_top->die_kset);
1196 DRM_ERROR("Couldn't register die_kset");
1200 for (ii = 0; ii < ARRAY_SIZE(ip_hw_attr); ii++)
1201 ip_hw_instance_attrs[ii] = &ip_hw_attr[ii].attr;
1202 ip_hw_instance_attrs[ii] = NULL;
1204 res = amdgpu_discovery_sysfs_recurse(adev);
1208 kobject_put(&adev->ip_top->kobj);
1212 /* -------------------------------------------------- */
1214 #define list_to_kobj(el) container_of(el, struct kobject, entry)
1216 static void amdgpu_discovery_sysfs_ip_hw_free(struct ip_hw_id *ip_hw_id)
1218 struct list_head *el, *tmp;
1219 struct kset *hw_id_kset;
1221 hw_id_kset = &ip_hw_id->hw_id_kset;
1222 spin_lock(&hw_id_kset->list_lock);
1223 list_for_each_prev_safe(el, tmp, &hw_id_kset->list) {
1225 spin_unlock(&hw_id_kset->list_lock);
1226 /* kobject is embedded in ip_hw_instance */
1227 kobject_put(list_to_kobj(el));
1228 spin_lock(&hw_id_kset->list_lock);
1230 spin_unlock(&hw_id_kset->list_lock);
1231 kobject_put(&ip_hw_id->hw_id_kset.kobj);
1234 static void amdgpu_discovery_sysfs_die_free(struct ip_die_entry *ip_die_entry)
1236 struct list_head *el, *tmp;
1237 struct kset *ip_kset;
1239 ip_kset = &ip_die_entry->ip_kset;
1240 spin_lock(&ip_kset->list_lock);
1241 list_for_each_prev_safe(el, tmp, &ip_kset->list) {
1243 spin_unlock(&ip_kset->list_lock);
1244 amdgpu_discovery_sysfs_ip_hw_free(to_ip_hw_id(list_to_kobj(el)));
1245 spin_lock(&ip_kset->list_lock);
1247 spin_unlock(&ip_kset->list_lock);
1248 kobject_put(&ip_die_entry->ip_kset.kobj);
1251 static void amdgpu_discovery_sysfs_fini(struct amdgpu_device *adev)
1253 struct list_head *el, *tmp;
1254 struct kset *die_kset;
1256 die_kset = &adev->ip_top->die_kset;
1257 spin_lock(&die_kset->list_lock);
1258 list_for_each_prev_safe(el, tmp, &die_kset->list) {
1260 spin_unlock(&die_kset->list_lock);
1261 amdgpu_discovery_sysfs_die_free(to_ip_die_entry(list_to_kobj(el)));
1262 spin_lock(&die_kset->list_lock);
1264 spin_unlock(&die_kset->list_lock);
1265 kobject_put(&adev->ip_top->die_kset.kobj);
1266 kobject_put(&adev->ip_top->kobj);
1269 /* ================================================== */
1271 static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
1273 uint8_t num_base_address, subrev, variant;
1274 struct binary_header *bhdr;
1275 struct ip_discovery_header *ihdr;
1276 struct die_header *dhdr;
1278 uint16_t die_offset;
1286 r = amdgpu_discovery_init(adev);
1288 DRM_ERROR("amdgpu_discovery_init failed\n");
1292 adev->gfx.xcc_mask = 0;
1293 adev->sdma.sdma_mask = 0;
1294 adev->vcn.inst_mask = 0;
1295 adev->jpeg.inst_mask = 0;
1296 bhdr = (struct binary_header *)adev->mman.discovery_bin;
1297 ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin +
1298 le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset));
1299 num_dies = le16_to_cpu(ihdr->num_dies);
1301 DRM_DEBUG("number of dies: %d\n", num_dies);
1303 for (i = 0; i < num_dies; i++) {
1304 die_offset = le16_to_cpu(ihdr->die_info[i].die_offset);
1305 dhdr = (struct die_header *)(adev->mman.discovery_bin + die_offset);
1306 num_ips = le16_to_cpu(dhdr->num_ips);
1307 ip_offset = die_offset + sizeof(*dhdr);
1309 if (le16_to_cpu(dhdr->die_id) != i) {
1310 DRM_ERROR("invalid die id %d, expected %d\n",
1311 le16_to_cpu(dhdr->die_id), i);
1315 DRM_DEBUG("number of hardware IPs on die%d: %d\n",
1316 le16_to_cpu(dhdr->die_id), num_ips);
1318 for (j = 0; j < num_ips; j++) {
1319 ip = (struct ip_v4 *)(adev->mman.discovery_bin + ip_offset);
1321 if (amdgpu_discovery_validate_ip(ip))
1324 num_base_address = ip->num_base_address;
1326 DRM_DEBUG("%s(%d) #%d v%d.%d.%d:\n",
1327 hw_id_names[le16_to_cpu(ip->hw_id)],
1328 le16_to_cpu(ip->hw_id),
1329 ip->instance_number,
1330 ip->major, ip->minor,
1333 if (le16_to_cpu(ip->hw_id) == VCN_HWID) {
1334 /* Bit [5:0]: original revision value
1335 * Bit [7:6]: en/decode capability:
1336 * 0b00 : VCN function normally
1337 * 0b10 : encode is disabled
1338 * 0b01 : decode is disabled
1340 if (adev->vcn.num_vcn_inst <
1341 AMDGPU_MAX_VCN_INSTANCES) {
1342 adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
1343 ip->revision & 0xc0;
1344 adev->vcn.num_vcn_inst++;
1345 adev->vcn.inst_mask |=
1346 (1U << ip->instance_number);
1347 adev->jpeg.inst_mask |=
1348 (1U << ip->instance_number);
1350 dev_err(adev->dev, "Too many VCN instances: %d vs %d\n",
1351 adev->vcn.num_vcn_inst + 1,
1352 AMDGPU_MAX_VCN_INSTANCES);
1354 ip->revision &= ~0xc0;
1356 if (le16_to_cpu(ip->hw_id) == SDMA0_HWID ||
1357 le16_to_cpu(ip->hw_id) == SDMA1_HWID ||
1358 le16_to_cpu(ip->hw_id) == SDMA2_HWID ||
1359 le16_to_cpu(ip->hw_id) == SDMA3_HWID) {
1360 if (adev->sdma.num_instances <
1361 AMDGPU_MAX_SDMA_INSTANCES) {
1362 adev->sdma.num_instances++;
1363 adev->sdma.sdma_mask |=
1364 (1U << ip->instance_number);
1366 dev_err(adev->dev, "Too many SDMA instances: %d vs %d\n",
1367 adev->sdma.num_instances + 1,
1368 AMDGPU_MAX_SDMA_INSTANCES);
1372 if (le16_to_cpu(ip->hw_id) == VPE_HWID) {
1373 if (adev->vpe.num_instances < AMDGPU_MAX_VPE_INSTANCES)
1374 adev->vpe.num_instances++;
1376 dev_err(adev->dev, "Too many VPE instances: %d vs %d\n",
1377 adev->vpe.num_instances + 1,
1378 AMDGPU_MAX_VPE_INSTANCES);
1381 if (le16_to_cpu(ip->hw_id) == UMC_HWID) {
1382 adev->gmc.num_umc++;
1383 adev->umc.node_inst_num++;
1386 if (le16_to_cpu(ip->hw_id) == GC_HWID)
1387 adev->gfx.xcc_mask |=
1388 (1U << ip->instance_number);
1390 for (k = 0; k < num_base_address; k++) {
1392 * convert the endianness of base addresses in place,
1393 * so that we don't need to convert them when accessing adev->reg_offset.
1395 if (ihdr->base_addr_64_bit)
1396 /* Truncate the 64bit base address from ip discovery
1397 * and only store lower 32bit ip base in reg_offset[].
1398 * Bits > 32 follows ASIC specific format, thus just
1399 * discard them and handle it within specific ASIC.
1400 * By this way reg_offset[] and related helpers can
1402 * The base address is in dwords, thus clear the
1403 * highest 2 bits to store.
1405 ip->base_address[k] =
1406 lower_32_bits(le64_to_cpu(ip->base_address_64[k])) & 0x3FFFFFFF;
1408 ip->base_address[k] = le32_to_cpu(ip->base_address[k]);
1409 DRM_DEBUG("\t0x%08x\n", ip->base_address[k]);
1412 for (hw_ip = 0; hw_ip < MAX_HWIP; hw_ip++) {
1413 if (hw_id_map[hw_ip] == le16_to_cpu(ip->hw_id) &&
1414 hw_id_map[hw_ip] != 0) {
1415 DRM_DEBUG("set register base offset for %s\n",
1416 hw_id_names[le16_to_cpu(ip->hw_id)]);
1417 adev->reg_offset[hw_ip][ip->instance_number] =
1419 /* Instance support is somewhat inconsistent.
1420 * SDMA is a good example. Sienna cichlid has 4 total
1421 * SDMA instances, each enumerated separately (HWIDs
1422 * 42, 43, 68, 69). Arcturus has 8 total SDMA instances,
1423 * but they are enumerated as multiple instances of the
1424 * same HWIDs (4x HWID 42, 4x HWID 43). UMC is another
1425 * example. On most chips there are multiple instances
1426 * with the same HWID.
1429 if (ihdr->version < 3) {
1433 subrev = ip->sub_revision;
1434 variant = ip->variant;
1437 adev->ip_versions[hw_ip]
1438 [ip->instance_number] =
1439 IP_VERSION_FULL(ip->major,
1448 if (ihdr->base_addr_64_bit)
1449 ip_offset += struct_size(ip, base_address_64, ip->num_base_address);
1451 ip_offset += struct_size(ip, base_address, ip->num_base_address);
1458 static void amdgpu_discovery_harvest_ip(struct amdgpu_device *adev)
1460 int vcn_harvest_count = 0;
1461 int umc_harvest_count = 0;
1464 * Harvest table does not fit Navi1x and legacy GPUs,
1465 * so read harvest bit per IP data structure to set
1466 * harvest configuration.
1468 if (amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(10, 2, 0) &&
1469 amdgpu_ip_version(adev, GC_HWIP, 0) != IP_VERSION(9, 4, 3) &&
1470 amdgpu_ip_version(adev, GC_HWIP, 0) != IP_VERSION(9, 4, 4)) {
1471 if ((adev->pdev->device == 0x731E &&
1472 (adev->pdev->revision == 0xC6 ||
1473 adev->pdev->revision == 0xC7)) ||
1474 (adev->pdev->device == 0x7340 &&
1475 adev->pdev->revision == 0xC9) ||
1476 (adev->pdev->device == 0x7360 &&
1477 adev->pdev->revision == 0xC7))
1478 amdgpu_discovery_read_harvest_bit_per_ip(adev,
1479 &vcn_harvest_count);
1481 amdgpu_discovery_read_from_harvest_table(adev,
1483 &umc_harvest_count);
1486 amdgpu_discovery_harvest_config_quirk(adev);
1488 if (vcn_harvest_count == adev->vcn.num_vcn_inst) {
1489 adev->harvest_ip_mask |= AMD_HARVEST_IP_VCN_MASK;
1490 adev->harvest_ip_mask |= AMD_HARVEST_IP_JPEG_MASK;
1493 if (umc_harvest_count < adev->gmc.num_umc) {
1494 adev->gmc.num_umc -= umc_harvest_count;
1499 struct gc_info_v1_0 v1;
1500 struct gc_info_v1_1 v1_1;
1501 struct gc_info_v1_2 v1_2;
1502 struct gc_info_v2_0 v2;
1503 struct gc_info_v2_1 v2_1;
1506 static int amdgpu_discovery_get_gfx_info(struct amdgpu_device *adev)
1508 struct binary_header *bhdr;
1509 union gc_info *gc_info;
1512 if (!adev->mman.discovery_bin) {
1513 DRM_ERROR("ip discovery uninitialized\n");
1517 bhdr = (struct binary_header *)adev->mman.discovery_bin;
1518 offset = le16_to_cpu(bhdr->table_list[GC].offset);
1523 gc_info = (union gc_info *)(adev->mman.discovery_bin + offset);
1525 switch (le16_to_cpu(gc_info->v1.header.version_major)) {
1527 adev->gfx.config.max_shader_engines = le32_to_cpu(gc_info->v1.gc_num_se);
1528 adev->gfx.config.max_cu_per_sh = 2 * (le32_to_cpu(gc_info->v1.gc_num_wgp0_per_sa) +
1529 le32_to_cpu(gc_info->v1.gc_num_wgp1_per_sa));
1530 adev->gfx.config.max_sh_per_se = le32_to_cpu(gc_info->v1.gc_num_sa_per_se);
1531 adev->gfx.config.max_backends_per_se = le32_to_cpu(gc_info->v1.gc_num_rb_per_se);
1532 adev->gfx.config.max_texture_channel_caches = le32_to_cpu(gc_info->v1.gc_num_gl2c);
1533 adev->gfx.config.max_gprs = le32_to_cpu(gc_info->v1.gc_num_gprs);
1534 adev->gfx.config.max_gs_threads = le32_to_cpu(gc_info->v1.gc_num_max_gs_thds);
1535 adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gc_info->v1.gc_gs_table_depth);
1536 adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gc_info->v1.gc_gsprim_buff_depth);
1537 adev->gfx.config.double_offchip_lds_buf = le32_to_cpu(gc_info->v1.gc_double_offchip_lds_buffer);
1538 adev->gfx.cu_info.wave_front_size = le32_to_cpu(gc_info->v1.gc_wave_size);
1539 adev->gfx.cu_info.max_waves_per_simd = le32_to_cpu(gc_info->v1.gc_max_waves_per_simd);
1540 adev->gfx.cu_info.max_scratch_slots_per_cu = le32_to_cpu(gc_info->v1.gc_max_scratch_slots_per_cu);
1541 adev->gfx.cu_info.lds_size = le32_to_cpu(gc_info->v1.gc_lds_size);
1542 adev->gfx.config.num_sc_per_sh = le32_to_cpu(gc_info->v1.gc_num_sc_per_se) /
1543 le32_to_cpu(gc_info->v1.gc_num_sa_per_se);
1544 adev->gfx.config.num_packer_per_sc = le32_to_cpu(gc_info->v1.gc_num_packer_per_sc);
1545 if (le16_to_cpu(gc_info->v1.header.version_minor) >= 1) {
1546 adev->gfx.config.gc_num_tcp_per_sa = le32_to_cpu(gc_info->v1_1.gc_num_tcp_per_sa);
1547 adev->gfx.config.gc_num_sdp_interface = le32_to_cpu(gc_info->v1_1.gc_num_sdp_interface);
1548 adev->gfx.config.gc_num_tcps = le32_to_cpu(gc_info->v1_1.gc_num_tcps);
1550 if (le16_to_cpu(gc_info->v1.header.version_minor) >= 2) {
1551 adev->gfx.config.gc_num_tcp_per_wpg = le32_to_cpu(gc_info->v1_2.gc_num_tcp_per_wpg);
1552 adev->gfx.config.gc_tcp_l1_size = le32_to_cpu(gc_info->v1_2.gc_tcp_l1_size);
1553 adev->gfx.config.gc_num_sqc_per_wgp = le32_to_cpu(gc_info->v1_2.gc_num_sqc_per_wgp);
1554 adev->gfx.config.gc_l1_instruction_cache_size_per_sqc = le32_to_cpu(gc_info->v1_2.gc_l1_instruction_cache_size_per_sqc);
1555 adev->gfx.config.gc_l1_data_cache_size_per_sqc = le32_to_cpu(gc_info->v1_2.gc_l1_data_cache_size_per_sqc);
1556 adev->gfx.config.gc_gl1c_per_sa = le32_to_cpu(gc_info->v1_2.gc_gl1c_per_sa);
1557 adev->gfx.config.gc_gl1c_size_per_instance = le32_to_cpu(gc_info->v1_2.gc_gl1c_size_per_instance);
1558 adev->gfx.config.gc_gl2c_per_gpu = le32_to_cpu(gc_info->v1_2.gc_gl2c_per_gpu);
1562 adev->gfx.config.max_shader_engines = le32_to_cpu(gc_info->v2.gc_num_se);
1563 adev->gfx.config.max_cu_per_sh = le32_to_cpu(gc_info->v2.gc_num_cu_per_sh);
1564 adev->gfx.config.max_sh_per_se = le32_to_cpu(gc_info->v2.gc_num_sh_per_se);
1565 adev->gfx.config.max_backends_per_se = le32_to_cpu(gc_info->v2.gc_num_rb_per_se);
1566 adev->gfx.config.max_texture_channel_caches = le32_to_cpu(gc_info->v2.gc_num_tccs);
1567 adev->gfx.config.max_gprs = le32_to_cpu(gc_info->v2.gc_num_gprs);
1568 adev->gfx.config.max_gs_threads = le32_to_cpu(gc_info->v2.gc_num_max_gs_thds);
1569 adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gc_info->v2.gc_gs_table_depth);
1570 adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gc_info->v2.gc_gsprim_buff_depth);
1571 adev->gfx.config.double_offchip_lds_buf = le32_to_cpu(gc_info->v2.gc_double_offchip_lds_buffer);
1572 adev->gfx.cu_info.wave_front_size = le32_to_cpu(gc_info->v2.gc_wave_size);
1573 adev->gfx.cu_info.max_waves_per_simd = le32_to_cpu(gc_info->v2.gc_max_waves_per_simd);
1574 adev->gfx.cu_info.max_scratch_slots_per_cu = le32_to_cpu(gc_info->v2.gc_max_scratch_slots_per_cu);
1575 adev->gfx.cu_info.lds_size = le32_to_cpu(gc_info->v2.gc_lds_size);
1576 adev->gfx.config.num_sc_per_sh = le32_to_cpu(gc_info->v2.gc_num_sc_per_se) /
1577 le32_to_cpu(gc_info->v2.gc_num_sh_per_se);
1578 adev->gfx.config.num_packer_per_sc = le32_to_cpu(gc_info->v2.gc_num_packer_per_sc);
1579 if (le16_to_cpu(gc_info->v2.header.version_minor) == 1) {
1580 adev->gfx.config.gc_num_tcp_per_sa = le32_to_cpu(gc_info->v2_1.gc_num_tcp_per_sh);
1581 adev->gfx.config.gc_tcp_size_per_cu = le32_to_cpu(gc_info->v2_1.gc_tcp_size_per_cu);
1582 adev->gfx.config.gc_num_sdp_interface = le32_to_cpu(gc_info->v2_1.gc_num_sdp_interface); /* per XCD */
1583 adev->gfx.config.gc_num_cu_per_sqc = le32_to_cpu(gc_info->v2_1.gc_num_cu_per_sqc);
1584 adev->gfx.config.gc_l1_instruction_cache_size_per_sqc = le32_to_cpu(gc_info->v2_1.gc_instruction_cache_size_per_sqc);
1585 adev->gfx.config.gc_l1_data_cache_size_per_sqc = le32_to_cpu(gc_info->v2_1.gc_scalar_data_cache_size_per_sqc);
1586 adev->gfx.config.gc_tcc_size = le32_to_cpu(gc_info->v2_1.gc_tcc_size); /* per XCD */
1591 "Unhandled GC info table %d.%d\n",
1592 le16_to_cpu(gc_info->v1.header.version_major),
1593 le16_to_cpu(gc_info->v1.header.version_minor));
1600 struct mall_info_v1_0 v1;
1601 struct mall_info_v2_0 v2;
1604 static int amdgpu_discovery_get_mall_info(struct amdgpu_device *adev)
1606 struct binary_header *bhdr;
1607 union mall_info *mall_info;
1608 u32 u, mall_size_per_umc, m_s_present, half_use;
1612 if (!adev->mman.discovery_bin) {
1613 DRM_ERROR("ip discovery uninitialized\n");
1617 bhdr = (struct binary_header *)adev->mman.discovery_bin;
1618 offset = le16_to_cpu(bhdr->table_list[MALL_INFO].offset);
1623 mall_info = (union mall_info *)(adev->mman.discovery_bin + offset);
1625 switch (le16_to_cpu(mall_info->v1.header.version_major)) {
1628 mall_size_per_umc = le32_to_cpu(mall_info->v1.mall_size_per_m);
1629 m_s_present = le32_to_cpu(mall_info->v1.m_s_present);
1630 half_use = le32_to_cpu(mall_info->v1.m_half_use);
1631 for (u = 0; u < adev->gmc.num_umc; u++) {
1632 if (m_s_present & (1 << u))
1633 mall_size += mall_size_per_umc * 2;
1634 else if (half_use & (1 << u))
1635 mall_size += mall_size_per_umc / 2;
1637 mall_size += mall_size_per_umc;
1639 adev->gmc.mall_size = mall_size;
1640 adev->gmc.m_half_use = half_use;
1643 mall_size_per_umc = le32_to_cpu(mall_info->v2.mall_size_per_umc);
1644 adev->gmc.mall_size = (uint64_t)mall_size_per_umc * adev->gmc.num_umc;
1648 "Unhandled MALL info table %d.%d\n",
1649 le16_to_cpu(mall_info->v1.header.version_major),
1650 le16_to_cpu(mall_info->v1.header.version_minor));
1657 struct vcn_info_v1_0 v1;
1660 static int amdgpu_discovery_get_vcn_info(struct amdgpu_device *adev)
1662 struct binary_header *bhdr;
1663 union vcn_info *vcn_info;
1667 if (!adev->mman.discovery_bin) {
1668 DRM_ERROR("ip discovery uninitialized\n");
1672 /* num_vcn_inst is currently limited to AMDGPU_MAX_VCN_INSTANCES
1673 * which is smaller than VCN_INFO_TABLE_MAX_NUM_INSTANCES
1674 * but that may change in the future with new GPUs so keep this
1675 * check for defensive purposes.
1677 if (adev->vcn.num_vcn_inst > VCN_INFO_TABLE_MAX_NUM_INSTANCES) {
1678 dev_err(adev->dev, "invalid vcn instances\n");
1682 bhdr = (struct binary_header *)adev->mman.discovery_bin;
1683 offset = le16_to_cpu(bhdr->table_list[VCN_INFO].offset);
1688 vcn_info = (union vcn_info *)(adev->mman.discovery_bin + offset);
1690 switch (le16_to_cpu(vcn_info->v1.header.version_major)) {
1692 /* num_vcn_inst is currently limited to AMDGPU_MAX_VCN_INSTANCES
1693 * so this won't overflow.
1695 for (v = 0; v < adev->vcn.num_vcn_inst; v++) {
1696 adev->vcn.vcn_codec_disable_mask[v] =
1697 le32_to_cpu(vcn_info->v1.instance_info[v].fuse_data.all_bits);
1702 "Unhandled VCN info table %d.%d\n",
1703 le16_to_cpu(vcn_info->v1.header.version_major),
1704 le16_to_cpu(vcn_info->v1.header.version_minor));
1711 struct nps_info_v1_0 v1;
1714 int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,
1716 struct amdgpu_gmc_memrange **ranges,
1719 struct amdgpu_gmc_memrange *mem_ranges;
1720 struct binary_header *bhdr;
1721 union nps_info *nps_info;
1725 if (!nps_type || !range_cnt || !ranges)
1728 if (!adev->mman.discovery_bin) {
1730 "fetch mem range failed, ip discovery uninitialized\n");
1734 bhdr = (struct binary_header *)adev->mman.discovery_bin;
1735 offset = le16_to_cpu(bhdr->table_list[NPS_INFO].offset);
1740 /* If verification fails, return as if NPS table doesn't exist */
1741 if (amdgpu_discovery_verify_npsinfo(adev, bhdr))
1744 nps_info = (union nps_info *)(adev->mman.discovery_bin + offset);
1746 switch (le16_to_cpu(nps_info->v1.header.version_major)) {
1748 *nps_type = nps_info->v1.nps_type;
1749 *range_cnt = nps_info->v1.count;
1750 mem_ranges = kvzalloc(
1751 *range_cnt * sizeof(struct amdgpu_gmc_memrange),
1753 for (i = 0; i < *range_cnt; i++) {
1754 mem_ranges[i].base_address =
1755 nps_info->v1.instance_info[i].base_address;
1756 mem_ranges[i].limit_address =
1757 nps_info->v1.instance_info[i].limit_address;
1758 mem_ranges[i].nid_mask = -1;
1759 mem_ranges[i].flags = 0;
1761 *ranges = mem_ranges;
1764 dev_err(adev->dev, "Unhandled NPS info table %d.%d\n",
1765 le16_to_cpu(nps_info->v1.header.version_major),
1766 le16_to_cpu(nps_info->v1.header.version_minor));
1773 static int amdgpu_discovery_set_common_ip_blocks(struct amdgpu_device *adev)
1775 /* what IP to use for this? */
1776 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
1777 case IP_VERSION(9, 0, 1):
1778 case IP_VERSION(9, 1, 0):
1779 case IP_VERSION(9, 2, 1):
1780 case IP_VERSION(9, 2, 2):
1781 case IP_VERSION(9, 3, 0):
1782 case IP_VERSION(9, 4, 0):
1783 case IP_VERSION(9, 4, 1):
1784 case IP_VERSION(9, 4, 2):
1785 case IP_VERSION(9, 4, 3):
1786 case IP_VERSION(9, 4, 4):
1787 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
1789 case IP_VERSION(10, 1, 10):
1790 case IP_VERSION(10, 1, 1):
1791 case IP_VERSION(10, 1, 2):
1792 case IP_VERSION(10, 1, 3):
1793 case IP_VERSION(10, 1, 4):
1794 case IP_VERSION(10, 3, 0):
1795 case IP_VERSION(10, 3, 1):
1796 case IP_VERSION(10, 3, 2):
1797 case IP_VERSION(10, 3, 3):
1798 case IP_VERSION(10, 3, 4):
1799 case IP_VERSION(10, 3, 5):
1800 case IP_VERSION(10, 3, 6):
1801 case IP_VERSION(10, 3, 7):
1802 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
1804 case IP_VERSION(11, 0, 0):
1805 case IP_VERSION(11, 0, 1):
1806 case IP_VERSION(11, 0, 2):
1807 case IP_VERSION(11, 0, 3):
1808 case IP_VERSION(11, 0, 4):
1809 case IP_VERSION(11, 5, 0):
1810 case IP_VERSION(11, 5, 1):
1811 case IP_VERSION(11, 5, 2):
1812 amdgpu_device_ip_block_add(adev, &soc21_common_ip_block);
1814 case IP_VERSION(12, 0, 0):
1815 case IP_VERSION(12, 0, 1):
1816 amdgpu_device_ip_block_add(adev, &soc24_common_ip_block);
1820 "Failed to add common ip block(GC_HWIP:0x%x)\n",
1821 amdgpu_ip_version(adev, GC_HWIP, 0));
1827 static int amdgpu_discovery_set_gmc_ip_blocks(struct amdgpu_device *adev)
1829 /* use GC or MMHUB IP version */
1830 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
1831 case IP_VERSION(9, 0, 1):
1832 case IP_VERSION(9, 1, 0):
1833 case IP_VERSION(9, 2, 1):
1834 case IP_VERSION(9, 2, 2):
1835 case IP_VERSION(9, 3, 0):
1836 case IP_VERSION(9, 4, 0):
1837 case IP_VERSION(9, 4, 1):
1838 case IP_VERSION(9, 4, 2):
1839 case IP_VERSION(9, 4, 3):
1840 case IP_VERSION(9, 4, 4):
1841 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
1843 case IP_VERSION(10, 1, 10):
1844 case IP_VERSION(10, 1, 1):
1845 case IP_VERSION(10, 1, 2):
1846 case IP_VERSION(10, 1, 3):
1847 case IP_VERSION(10, 1, 4):
1848 case IP_VERSION(10, 3, 0):
1849 case IP_VERSION(10, 3, 1):
1850 case IP_VERSION(10, 3, 2):
1851 case IP_VERSION(10, 3, 3):
1852 case IP_VERSION(10, 3, 4):
1853 case IP_VERSION(10, 3, 5):
1854 case IP_VERSION(10, 3, 6):
1855 case IP_VERSION(10, 3, 7):
1856 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
1858 case IP_VERSION(11, 0, 0):
1859 case IP_VERSION(11, 0, 1):
1860 case IP_VERSION(11, 0, 2):
1861 case IP_VERSION(11, 0, 3):
1862 case IP_VERSION(11, 0, 4):
1863 case IP_VERSION(11, 5, 0):
1864 case IP_VERSION(11, 5, 1):
1865 case IP_VERSION(11, 5, 2):
1866 amdgpu_device_ip_block_add(adev, &gmc_v11_0_ip_block);
1868 case IP_VERSION(12, 0, 0):
1869 case IP_VERSION(12, 0, 1):
1870 amdgpu_device_ip_block_add(adev, &gmc_v12_0_ip_block);
1873 dev_err(adev->dev, "Failed to add gmc ip block(GC_HWIP:0x%x)\n",
1874 amdgpu_ip_version(adev, GC_HWIP, 0));
1880 static int amdgpu_discovery_set_ih_ip_blocks(struct amdgpu_device *adev)
1882 switch (amdgpu_ip_version(adev, OSSSYS_HWIP, 0)) {
1883 case IP_VERSION(4, 0, 0):
1884 case IP_VERSION(4, 0, 1):
1885 case IP_VERSION(4, 1, 0):
1886 case IP_VERSION(4, 1, 1):
1887 case IP_VERSION(4, 3, 0):
1888 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
1890 case IP_VERSION(4, 2, 0):
1891 case IP_VERSION(4, 2, 1):
1892 case IP_VERSION(4, 4, 0):
1893 case IP_VERSION(4, 4, 2):
1894 case IP_VERSION(4, 4, 5):
1895 amdgpu_device_ip_block_add(adev, &vega20_ih_ip_block);
1897 case IP_VERSION(5, 0, 0):
1898 case IP_VERSION(5, 0, 1):
1899 case IP_VERSION(5, 0, 2):
1900 case IP_VERSION(5, 0, 3):
1901 case IP_VERSION(5, 2, 0):
1902 case IP_VERSION(5, 2, 1):
1903 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
1905 case IP_VERSION(6, 0, 0):
1906 case IP_VERSION(6, 0, 1):
1907 case IP_VERSION(6, 0, 2):
1908 amdgpu_device_ip_block_add(adev, &ih_v6_0_ip_block);
1910 case IP_VERSION(6, 1, 0):
1911 amdgpu_device_ip_block_add(adev, &ih_v6_1_ip_block);
1913 case IP_VERSION(7, 0, 0):
1914 amdgpu_device_ip_block_add(adev, &ih_v7_0_ip_block);
1918 "Failed to add ih ip block(OSSSYS_HWIP:0x%x)\n",
1919 amdgpu_ip_version(adev, OSSSYS_HWIP, 0));
1925 static int amdgpu_discovery_set_psp_ip_blocks(struct amdgpu_device *adev)
1927 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
1928 case IP_VERSION(9, 0, 0):
1929 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
1931 case IP_VERSION(10, 0, 0):
1932 case IP_VERSION(10, 0, 1):
1933 amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
1935 case IP_VERSION(11, 0, 0):
1936 case IP_VERSION(11, 0, 2):
1937 case IP_VERSION(11, 0, 4):
1938 case IP_VERSION(11, 0, 5):
1939 case IP_VERSION(11, 0, 9):
1940 case IP_VERSION(11, 0, 7):
1941 case IP_VERSION(11, 0, 11):
1942 case IP_VERSION(11, 0, 12):
1943 case IP_VERSION(11, 0, 13):
1944 case IP_VERSION(11, 5, 0):
1945 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
1947 case IP_VERSION(11, 0, 8):
1948 amdgpu_device_ip_block_add(adev, &psp_v11_0_8_ip_block);
1950 case IP_VERSION(11, 0, 3):
1951 case IP_VERSION(12, 0, 1):
1952 amdgpu_device_ip_block_add(adev, &psp_v12_0_ip_block);
1954 case IP_VERSION(13, 0, 0):
1955 case IP_VERSION(13, 0, 1):
1956 case IP_VERSION(13, 0, 2):
1957 case IP_VERSION(13, 0, 3):
1958 case IP_VERSION(13, 0, 5):
1959 case IP_VERSION(13, 0, 6):
1960 case IP_VERSION(13, 0, 7):
1961 case IP_VERSION(13, 0, 8):
1962 case IP_VERSION(13, 0, 10):
1963 case IP_VERSION(13, 0, 11):
1964 case IP_VERSION(13, 0, 14):
1965 case IP_VERSION(14, 0, 0):
1966 case IP_VERSION(14, 0, 1):
1967 case IP_VERSION(14, 0, 4):
1968 amdgpu_device_ip_block_add(adev, &psp_v13_0_ip_block);
1970 case IP_VERSION(13, 0, 4):
1971 amdgpu_device_ip_block_add(adev, &psp_v13_0_4_ip_block);
1973 case IP_VERSION(14, 0, 2):
1974 case IP_VERSION(14, 0, 3):
1975 amdgpu_device_ip_block_add(adev, &psp_v14_0_ip_block);
1979 "Failed to add psp ip block(MP0_HWIP:0x%x)\n",
1980 amdgpu_ip_version(adev, MP0_HWIP, 0));
1986 static int amdgpu_discovery_set_smu_ip_blocks(struct amdgpu_device *adev)
1988 switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
1989 case IP_VERSION(9, 0, 0):
1990 case IP_VERSION(10, 0, 0):
1991 case IP_VERSION(10, 0, 1):
1992 case IP_VERSION(11, 0, 2):
1993 if (adev->asic_type == CHIP_ARCTURUS)
1994 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
1996 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
1998 case IP_VERSION(11, 0, 0):
1999 case IP_VERSION(11, 0, 5):
2000 case IP_VERSION(11, 0, 9):
2001 case IP_VERSION(11, 0, 7):
2002 case IP_VERSION(11, 0, 8):
2003 case IP_VERSION(11, 0, 11):
2004 case IP_VERSION(11, 0, 12):
2005 case IP_VERSION(11, 0, 13):
2006 case IP_VERSION(11, 5, 0):
2007 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
2009 case IP_VERSION(12, 0, 0):
2010 case IP_VERSION(12, 0, 1):
2011 amdgpu_device_ip_block_add(adev, &smu_v12_0_ip_block);
2013 case IP_VERSION(13, 0, 0):
2014 case IP_VERSION(13, 0, 1):
2015 case IP_VERSION(13, 0, 2):
2016 case IP_VERSION(13, 0, 3):
2017 case IP_VERSION(13, 0, 4):
2018 case IP_VERSION(13, 0, 5):
2019 case IP_VERSION(13, 0, 6):
2020 case IP_VERSION(13, 0, 7):
2021 case IP_VERSION(13, 0, 8):
2022 case IP_VERSION(13, 0, 10):
2023 case IP_VERSION(13, 0, 11):
2024 case IP_VERSION(13, 0, 14):
2025 amdgpu_device_ip_block_add(adev, &smu_v13_0_ip_block);
2027 case IP_VERSION(14, 0, 0):
2028 case IP_VERSION(14, 0, 1):
2029 case IP_VERSION(14, 0, 2):
2030 case IP_VERSION(14, 0, 3):
2031 case IP_VERSION(14, 0, 4):
2032 amdgpu_device_ip_block_add(adev, &smu_v14_0_ip_block);
2036 "Failed to add smu ip block(MP1_HWIP:0x%x)\n",
2037 amdgpu_ip_version(adev, MP1_HWIP, 0));
2043 #if defined(CONFIG_DRM_AMD_DC)
2044 static void amdgpu_discovery_set_sriov_display(struct amdgpu_device *adev)
2046 amdgpu_device_set_sriov_virtual_display(adev);
2047 amdgpu_device_ip_block_add(adev, &amdgpu_vkms_ip_block);
2051 static int amdgpu_discovery_set_display_ip_blocks(struct amdgpu_device *adev)
2053 if (adev->enable_virtual_display) {
2054 amdgpu_device_ip_block_add(adev, &amdgpu_vkms_ip_block);
2058 if (!amdgpu_device_has_dc_support(adev))
2061 #if defined(CONFIG_DRM_AMD_DC)
2062 if (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
2063 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
2064 case IP_VERSION(1, 0, 0):
2065 case IP_VERSION(1, 0, 1):
2066 case IP_VERSION(2, 0, 2):
2067 case IP_VERSION(2, 0, 0):
2068 case IP_VERSION(2, 0, 3):
2069 case IP_VERSION(2, 1, 0):
2070 case IP_VERSION(3, 0, 0):
2071 case IP_VERSION(3, 0, 2):
2072 case IP_VERSION(3, 0, 3):
2073 case IP_VERSION(3, 0, 1):
2074 case IP_VERSION(3, 1, 2):
2075 case IP_VERSION(3, 1, 3):
2076 case IP_VERSION(3, 1, 4):
2077 case IP_VERSION(3, 1, 5):
2078 case IP_VERSION(3, 1, 6):
2079 case IP_VERSION(3, 2, 0):
2080 case IP_VERSION(3, 2, 1):
2081 case IP_VERSION(3, 5, 0):
2082 case IP_VERSION(3, 5, 1):
2083 case IP_VERSION(4, 1, 0):
2084 /* TODO: Fix IP version. DC code expects version 4.0.1 */
2085 if (adev->ip_versions[DCE_HWIP][0] == IP_VERSION(4, 1, 0))
2086 adev->ip_versions[DCE_HWIP][0] = IP_VERSION(4, 0, 1);
2088 if (amdgpu_sriov_vf(adev))
2089 amdgpu_discovery_set_sriov_display(adev);
2091 amdgpu_device_ip_block_add(adev, &dm_ip_block);
2095 "Failed to add dm ip block(DCE_HWIP:0x%x)\n",
2096 amdgpu_ip_version(adev, DCE_HWIP, 0));
2099 } else if (amdgpu_ip_version(adev, DCI_HWIP, 0)) {
2100 switch (amdgpu_ip_version(adev, DCI_HWIP, 0)) {
2101 case IP_VERSION(12, 0, 0):
2102 case IP_VERSION(12, 0, 1):
2103 case IP_VERSION(12, 1, 0):
2104 if (amdgpu_sriov_vf(adev))
2105 amdgpu_discovery_set_sriov_display(adev);
2107 amdgpu_device_ip_block_add(adev, &dm_ip_block);
2111 "Failed to add dm ip block(DCI_HWIP:0x%x)\n",
2112 amdgpu_ip_version(adev, DCI_HWIP, 0));
2120 static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
2122 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
2123 case IP_VERSION(9, 0, 1):
2124 case IP_VERSION(9, 1, 0):
2125 case IP_VERSION(9, 2, 1):
2126 case IP_VERSION(9, 2, 2):
2127 case IP_VERSION(9, 3, 0):
2128 case IP_VERSION(9, 4, 0):
2129 case IP_VERSION(9, 4, 1):
2130 case IP_VERSION(9, 4, 2):
2131 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
2133 case IP_VERSION(9, 4, 3):
2134 case IP_VERSION(9, 4, 4):
2135 amdgpu_device_ip_block_add(adev, &gfx_v9_4_3_ip_block);
2137 case IP_VERSION(10, 1, 10):
2138 case IP_VERSION(10, 1, 2):
2139 case IP_VERSION(10, 1, 1):
2140 case IP_VERSION(10, 1, 3):
2141 case IP_VERSION(10, 1, 4):
2142 case IP_VERSION(10, 3, 0):
2143 case IP_VERSION(10, 3, 2):
2144 case IP_VERSION(10, 3, 1):
2145 case IP_VERSION(10, 3, 4):
2146 case IP_VERSION(10, 3, 5):
2147 case IP_VERSION(10, 3, 6):
2148 case IP_VERSION(10, 3, 3):
2149 case IP_VERSION(10, 3, 7):
2150 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
2152 case IP_VERSION(11, 0, 0):
2153 case IP_VERSION(11, 0, 1):
2154 case IP_VERSION(11, 0, 2):
2155 case IP_VERSION(11, 0, 3):
2156 case IP_VERSION(11, 0, 4):
2157 case IP_VERSION(11, 5, 0):
2158 case IP_VERSION(11, 5, 1):
2159 case IP_VERSION(11, 5, 2):
2160 amdgpu_device_ip_block_add(adev, &gfx_v11_0_ip_block);
2162 case IP_VERSION(12, 0, 0):
2163 case IP_VERSION(12, 0, 1):
2164 amdgpu_device_ip_block_add(adev, &gfx_v12_0_ip_block);
2167 dev_err(adev->dev, "Failed to add gfx ip block(GC_HWIP:0x%x)\n",
2168 amdgpu_ip_version(adev, GC_HWIP, 0));
2174 static int amdgpu_discovery_set_sdma_ip_blocks(struct amdgpu_device *adev)
2176 switch (amdgpu_ip_version(adev, SDMA0_HWIP, 0)) {
2177 case IP_VERSION(4, 0, 0):
2178 case IP_VERSION(4, 0, 1):
2179 case IP_VERSION(4, 1, 0):
2180 case IP_VERSION(4, 1, 1):
2181 case IP_VERSION(4, 1, 2):
2182 case IP_VERSION(4, 2, 0):
2183 case IP_VERSION(4, 2, 2):
2184 case IP_VERSION(4, 4, 0):
2185 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
2187 case IP_VERSION(4, 4, 2):
2188 case IP_VERSION(4, 4, 5):
2189 amdgpu_device_ip_block_add(adev, &sdma_v4_4_2_ip_block);
2191 case IP_VERSION(5, 0, 0):
2192 case IP_VERSION(5, 0, 1):
2193 case IP_VERSION(5, 0, 2):
2194 case IP_VERSION(5, 0, 5):
2195 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
2197 case IP_VERSION(5, 2, 0):
2198 case IP_VERSION(5, 2, 2):
2199 case IP_VERSION(5, 2, 4):
2200 case IP_VERSION(5, 2, 5):
2201 case IP_VERSION(5, 2, 6):
2202 case IP_VERSION(5, 2, 3):
2203 case IP_VERSION(5, 2, 1):
2204 case IP_VERSION(5, 2, 7):
2205 amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
2207 case IP_VERSION(6, 0, 0):
2208 case IP_VERSION(6, 0, 1):
2209 case IP_VERSION(6, 0, 2):
2210 case IP_VERSION(6, 0, 3):
2211 case IP_VERSION(6, 1, 0):
2212 case IP_VERSION(6, 1, 1):
2213 case IP_VERSION(6, 1, 2):
2214 amdgpu_device_ip_block_add(adev, &sdma_v6_0_ip_block);
2216 case IP_VERSION(7, 0, 0):
2217 case IP_VERSION(7, 0, 1):
2218 amdgpu_device_ip_block_add(adev, &sdma_v7_0_ip_block);
2222 "Failed to add sdma ip block(SDMA0_HWIP:0x%x)\n",
2223 amdgpu_ip_version(adev, SDMA0_HWIP, 0));
2229 static int amdgpu_discovery_set_mm_ip_blocks(struct amdgpu_device *adev)
2231 if (amdgpu_ip_version(adev, VCE_HWIP, 0)) {
2232 switch (amdgpu_ip_version(adev, UVD_HWIP, 0)) {
2233 case IP_VERSION(7, 0, 0):
2234 case IP_VERSION(7, 2, 0):
2235 /* UVD is not supported on vega20 SR-IOV */
2236 if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev)))
2237 amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block);
2241 "Failed to add uvd v7 ip block(UVD_HWIP:0x%x)\n",
2242 amdgpu_ip_version(adev, UVD_HWIP, 0));
2245 switch (amdgpu_ip_version(adev, VCE_HWIP, 0)) {
2246 case IP_VERSION(4, 0, 0):
2247 case IP_VERSION(4, 1, 0):
2248 /* VCE is not supported on vega20 SR-IOV */
2249 if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev)))
2250 amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block);
2254 "Failed to add VCE v4 ip block(VCE_HWIP:0x%x)\n",
2255 amdgpu_ip_version(adev, VCE_HWIP, 0));
2259 switch (amdgpu_ip_version(adev, UVD_HWIP, 0)) {
2260 case IP_VERSION(1, 0, 0):
2261 case IP_VERSION(1, 0, 1):
2262 amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
2264 case IP_VERSION(2, 0, 0):
2265 case IP_VERSION(2, 0, 2):
2266 case IP_VERSION(2, 2, 0):
2267 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
2268 if (!amdgpu_sriov_vf(adev))
2269 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
2271 case IP_VERSION(2, 0, 3):
2273 case IP_VERSION(2, 5, 0):
2274 amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block);
2275 amdgpu_device_ip_block_add(adev, &jpeg_v2_5_ip_block);
2277 case IP_VERSION(2, 6, 0):
2278 amdgpu_device_ip_block_add(adev, &vcn_v2_6_ip_block);
2279 amdgpu_device_ip_block_add(adev, &jpeg_v2_6_ip_block);
2281 case IP_VERSION(3, 0, 0):
2282 case IP_VERSION(3, 0, 16):
2283 case IP_VERSION(3, 1, 1):
2284 case IP_VERSION(3, 1, 2):
2285 case IP_VERSION(3, 0, 2):
2286 amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
2287 if (!amdgpu_sriov_vf(adev))
2288 amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
2290 case IP_VERSION(3, 0, 33):
2291 amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
2293 case IP_VERSION(4, 0, 0):
2294 case IP_VERSION(4, 0, 2):
2295 case IP_VERSION(4, 0, 4):
2296 amdgpu_device_ip_block_add(adev, &vcn_v4_0_ip_block);
2297 amdgpu_device_ip_block_add(adev, &jpeg_v4_0_ip_block);
2299 case IP_VERSION(4, 0, 3):
2300 amdgpu_device_ip_block_add(adev, &vcn_v4_0_3_ip_block);
2301 amdgpu_device_ip_block_add(adev, &jpeg_v4_0_3_ip_block);
2303 case IP_VERSION(4, 0, 5):
2304 case IP_VERSION(4, 0, 6):
2305 amdgpu_device_ip_block_add(adev, &vcn_v4_0_5_ip_block);
2306 amdgpu_device_ip_block_add(adev, &jpeg_v4_0_5_ip_block);
2308 case IP_VERSION(5, 0, 0):
2309 amdgpu_device_ip_block_add(adev, &vcn_v5_0_0_ip_block);
2310 amdgpu_device_ip_block_add(adev, &jpeg_v5_0_0_ip_block);
2314 "Failed to add vcn/jpeg ip block(UVD_HWIP:0x%x)\n",
2315 amdgpu_ip_version(adev, UVD_HWIP, 0));
2322 static int amdgpu_discovery_set_mes_ip_blocks(struct amdgpu_device *adev)
2324 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
2325 case IP_VERSION(11, 0, 0):
2326 case IP_VERSION(11, 0, 1):
2327 case IP_VERSION(11, 0, 2):
2328 case IP_VERSION(11, 0, 3):
2329 case IP_VERSION(11, 0, 4):
2330 case IP_VERSION(11, 5, 0):
2331 case IP_VERSION(11, 5, 1):
2332 case IP_VERSION(11, 5, 2):
2333 amdgpu_device_ip_block_add(adev, &mes_v11_0_ip_block);
2334 adev->enable_mes = true;
2335 adev->enable_mes_kiq = true;
2337 case IP_VERSION(12, 0, 0):
2338 case IP_VERSION(12, 0, 1):
2339 amdgpu_device_ip_block_add(adev, &mes_v12_0_ip_block);
2340 adev->enable_mes = true;
2341 adev->enable_mes_kiq = true;
2343 adev->enable_uni_mes = true;
2351 static void amdgpu_discovery_init_soc_config(struct amdgpu_device *adev)
2353 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
2354 case IP_VERSION(9, 4, 3):
2355 case IP_VERSION(9, 4, 4):
2356 aqua_vanjaram_init_soc_config(adev);
2363 static int amdgpu_discovery_set_vpe_ip_blocks(struct amdgpu_device *adev)
2365 switch (amdgpu_ip_version(adev, VPE_HWIP, 0)) {
2366 case IP_VERSION(6, 1, 0):
2367 case IP_VERSION(6, 1, 1):
2368 case IP_VERSION(6, 1, 3):
2369 amdgpu_device_ip_block_add(adev, &vpe_v6_1_ip_block);
2378 static int amdgpu_discovery_set_umsch_mm_ip_blocks(struct amdgpu_device *adev)
2380 switch (amdgpu_ip_version(adev, VCN_HWIP, 0)) {
2381 case IP_VERSION(4, 0, 5):
2382 case IP_VERSION(4, 0, 6):
2383 if (amdgpu_umsch_mm & 0x1) {
2384 amdgpu_device_ip_block_add(adev, &umsch_mm_v4_0_ip_block);
2385 adev->enable_umsch_mm = true;
2395 static int amdgpu_discovery_set_isp_ip_blocks(struct amdgpu_device *adev)
2397 #if defined(CONFIG_DRM_AMD_ISP)
2398 switch (amdgpu_ip_version(adev, ISP_HWIP, 0)) {
2399 case IP_VERSION(4, 1, 0):
2400 amdgpu_device_ip_block_add(adev, &isp_v4_1_0_ip_block);
2402 case IP_VERSION(4, 1, 1):
2403 amdgpu_device_ip_block_add(adev, &isp_v4_1_1_ip_block);
2413 int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
2417 switch (adev->asic_type) {
2419 vega10_reg_base_init(adev);
2420 adev->sdma.num_instances = 2;
2421 adev->gmc.num_umc = 4;
2422 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 0, 0);
2423 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 0, 0);
2424 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 0, 0);
2425 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 0, 0);
2426 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 0, 0);
2427 adev->ip_versions[SDMA1_HWIP][0] = IP_VERSION(4, 0, 0);
2428 adev->ip_versions[DF_HWIP][0] = IP_VERSION(2, 1, 0);
2429 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(6, 1, 0);
2430 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 0, 0);
2431 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(9, 0, 0);
2432 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(9, 0, 0);
2433 adev->ip_versions[THM_HWIP][0] = IP_VERSION(9, 0, 0);
2434 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(9, 0, 0);
2435 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 0, 1);
2436 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(7, 0, 0);
2437 adev->ip_versions[VCE_HWIP][0] = IP_VERSION(4, 0, 0);
2438 adev->ip_versions[DCI_HWIP][0] = IP_VERSION(12, 0, 0);
2441 vega10_reg_base_init(adev);
2442 adev->sdma.num_instances = 2;
2443 adev->gmc.num_umc = 4;
2444 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 3, 0);
2445 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 3, 0);
2446 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 0, 1);
2447 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 0, 1);
2448 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 0, 1);
2449 adev->ip_versions[SDMA1_HWIP][0] = IP_VERSION(4, 0, 1);
2450 adev->ip_versions[DF_HWIP][0] = IP_VERSION(2, 5, 0);
2451 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(6, 2, 0);
2452 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 1, 0);
2453 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(9, 0, 0);
2454 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(9, 0, 0);
2455 adev->ip_versions[THM_HWIP][0] = IP_VERSION(9, 0, 0);
2456 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(9, 0, 1);
2457 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 2, 1);
2458 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(7, 0, 0);
2459 adev->ip_versions[VCE_HWIP][0] = IP_VERSION(4, 0, 0);
2460 adev->ip_versions[DCI_HWIP][0] = IP_VERSION(12, 0, 1);
2463 vega10_reg_base_init(adev);
2464 adev->sdma.num_instances = 1;
2465 adev->vcn.num_vcn_inst = 1;
2466 adev->gmc.num_umc = 2;
2467 if (adev->apu_flags & AMD_APU_IS_RAVEN2) {
2468 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 2, 0);
2469 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 2, 0);
2470 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 1, 1);
2471 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 1, 1);
2472 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 1, 1);
2473 adev->ip_versions[DF_HWIP][0] = IP_VERSION(2, 1, 1);
2474 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 0, 1);
2475 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(7, 5, 0);
2476 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(10, 0, 1);
2477 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(10, 0, 1);
2478 adev->ip_versions[THM_HWIP][0] = IP_VERSION(10, 1, 0);
2479 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(10, 0, 1);
2480 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 2, 2);
2481 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(1, 0, 1);
2482 adev->ip_versions[DCE_HWIP][0] = IP_VERSION(1, 0, 1);
2484 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 1, 0);
2485 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 1, 0);
2486 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 1, 0);
2487 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 1, 0);
2488 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 1, 0);
2489 adev->ip_versions[DF_HWIP][0] = IP_VERSION(2, 1, 0);
2490 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 0, 0);
2491 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(7, 0, 0);
2492 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(10, 0, 0);
2493 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(10, 0, 0);
2494 adev->ip_versions[THM_HWIP][0] = IP_VERSION(10, 0, 0);
2495 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(10, 0, 0);
2496 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 1, 0);
2497 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(1, 0, 0);
2498 adev->ip_versions[DCE_HWIP][0] = IP_VERSION(1, 0, 0);
2502 vega20_reg_base_init(adev);
2503 adev->sdma.num_instances = 2;
2504 adev->gmc.num_umc = 8;
2505 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 4, 0);
2506 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 4, 0);
2507 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 2, 0);
2508 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 2, 0);
2509 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 2, 0);
2510 adev->ip_versions[SDMA1_HWIP][0] = IP_VERSION(4, 2, 0);
2511 adev->ip_versions[DF_HWIP][0] = IP_VERSION(3, 6, 0);
2512 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 4, 0);
2513 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 1, 1);
2514 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(11, 0, 2);
2515 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(11, 0, 2);
2516 adev->ip_versions[THM_HWIP][0] = IP_VERSION(11, 0, 2);
2517 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(11, 0, 2);
2518 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 4, 0);
2519 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(7, 2, 0);
2520 adev->ip_versions[UVD_HWIP][1] = IP_VERSION(7, 2, 0);
2521 adev->ip_versions[VCE_HWIP][0] = IP_VERSION(4, 1, 0);
2522 adev->ip_versions[DCI_HWIP][0] = IP_VERSION(12, 1, 0);
2525 arct_reg_base_init(adev);
2526 adev->sdma.num_instances = 8;
2527 adev->vcn.num_vcn_inst = 2;
2528 adev->gmc.num_umc = 8;
2529 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 4, 1);
2530 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 4, 1);
2531 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 2, 1);
2532 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 2, 1);
2533 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 2, 2);
2534 adev->ip_versions[SDMA1_HWIP][0] = IP_VERSION(4, 2, 2);
2535 adev->ip_versions[SDMA1_HWIP][1] = IP_VERSION(4, 2, 2);
2536 adev->ip_versions[SDMA1_HWIP][2] = IP_VERSION(4, 2, 2);
2537 adev->ip_versions[SDMA1_HWIP][3] = IP_VERSION(4, 2, 2);
2538 adev->ip_versions[SDMA1_HWIP][4] = IP_VERSION(4, 2, 2);
2539 adev->ip_versions[SDMA1_HWIP][5] = IP_VERSION(4, 2, 2);
2540 adev->ip_versions[SDMA1_HWIP][6] = IP_VERSION(4, 2, 2);
2541 adev->ip_versions[DF_HWIP][0] = IP_VERSION(3, 6, 1);
2542 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 4, 1);
2543 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 1, 2);
2544 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(11, 0, 4);
2545 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(11, 0, 2);
2546 adev->ip_versions[THM_HWIP][0] = IP_VERSION(11, 0, 3);
2547 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(11, 0, 3);
2548 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 4, 1);
2549 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(2, 5, 0);
2550 adev->ip_versions[UVD_HWIP][1] = IP_VERSION(2, 5, 0);
2552 case CHIP_ALDEBARAN:
2553 aldebaran_reg_base_init(adev);
2554 adev->sdma.num_instances = 5;
2555 adev->vcn.num_vcn_inst = 2;
2556 adev->gmc.num_umc = 4;
2557 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 4, 2);
2558 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 4, 2);
2559 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 4, 0);
2560 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 4, 0);
2561 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 4, 0);
2562 adev->ip_versions[SDMA0_HWIP][1] = IP_VERSION(4, 4, 0);
2563 adev->ip_versions[SDMA0_HWIP][2] = IP_VERSION(4, 4, 0);
2564 adev->ip_versions[SDMA0_HWIP][3] = IP_VERSION(4, 4, 0);
2565 adev->ip_versions[SDMA0_HWIP][4] = IP_VERSION(4, 4, 0);
2566 adev->ip_versions[DF_HWIP][0] = IP_VERSION(3, 6, 2);
2567 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 4, 4);
2568 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 7, 0);
2569 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(13, 0, 2);
2570 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(13, 0, 2);
2571 adev->ip_versions[THM_HWIP][0] = IP_VERSION(13, 0, 2);
2572 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(13, 0, 2);
2573 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 4, 2);
2574 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(2, 6, 0);
2575 adev->ip_versions[UVD_HWIP][1] = IP_VERSION(2, 6, 0);
2576 adev->ip_versions[XGMI_HWIP][0] = IP_VERSION(6, 1, 0);
2579 r = amdgpu_discovery_reg_base_init(adev);
2583 amdgpu_discovery_harvest_ip(adev);
2584 amdgpu_discovery_get_gfx_info(adev);
2585 amdgpu_discovery_get_mall_info(adev);
2586 amdgpu_discovery_get_vcn_info(adev);
2590 amdgpu_discovery_init_soc_config(adev);
2591 amdgpu_discovery_sysfs_init(adev);
2593 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
2594 case IP_VERSION(9, 0, 1):
2595 case IP_VERSION(9, 2, 1):
2596 case IP_VERSION(9, 4, 0):
2597 case IP_VERSION(9, 4, 1):
2598 case IP_VERSION(9, 4, 2):
2599 case IP_VERSION(9, 4, 3):
2600 case IP_VERSION(9, 4, 4):
2601 adev->family = AMDGPU_FAMILY_AI;
2603 case IP_VERSION(9, 1, 0):
2604 case IP_VERSION(9, 2, 2):
2605 case IP_VERSION(9, 3, 0):
2606 adev->family = AMDGPU_FAMILY_RV;
2608 case IP_VERSION(10, 1, 10):
2609 case IP_VERSION(10, 1, 1):
2610 case IP_VERSION(10, 1, 2):
2611 case IP_VERSION(10, 1, 3):
2612 case IP_VERSION(10, 1, 4):
2613 case IP_VERSION(10, 3, 0):
2614 case IP_VERSION(10, 3, 2):
2615 case IP_VERSION(10, 3, 4):
2616 case IP_VERSION(10, 3, 5):
2617 adev->family = AMDGPU_FAMILY_NV;
2619 case IP_VERSION(10, 3, 1):
2620 adev->family = AMDGPU_FAMILY_VGH;
2621 adev->apu_flags |= AMD_APU_IS_VANGOGH;
2623 case IP_VERSION(10, 3, 3):
2624 adev->family = AMDGPU_FAMILY_YC;
2626 case IP_VERSION(10, 3, 6):
2627 adev->family = AMDGPU_FAMILY_GC_10_3_6;
2629 case IP_VERSION(10, 3, 7):
2630 adev->family = AMDGPU_FAMILY_GC_10_3_7;
2632 case IP_VERSION(11, 0, 0):
2633 case IP_VERSION(11, 0, 2):
2634 case IP_VERSION(11, 0, 3):
2635 adev->family = AMDGPU_FAMILY_GC_11_0_0;
2637 case IP_VERSION(11, 0, 1):
2638 case IP_VERSION(11, 0, 4):
2639 adev->family = AMDGPU_FAMILY_GC_11_0_1;
2641 case IP_VERSION(11, 5, 0):
2642 case IP_VERSION(11, 5, 1):
2643 case IP_VERSION(11, 5, 2):
2644 adev->family = AMDGPU_FAMILY_GC_11_5_0;
2646 case IP_VERSION(12, 0, 0):
2647 case IP_VERSION(12, 0, 1):
2648 adev->family = AMDGPU_FAMILY_GC_12_0_0;
2654 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
2655 case IP_VERSION(9, 1, 0):
2656 case IP_VERSION(9, 2, 2):
2657 case IP_VERSION(9, 3, 0):
2658 case IP_VERSION(10, 1, 3):
2659 case IP_VERSION(10, 1, 4):
2660 case IP_VERSION(10, 3, 1):
2661 case IP_VERSION(10, 3, 3):
2662 case IP_VERSION(10, 3, 6):
2663 case IP_VERSION(10, 3, 7):
2664 case IP_VERSION(11, 0, 1):
2665 case IP_VERSION(11, 0, 4):
2666 case IP_VERSION(11, 5, 0):
2667 case IP_VERSION(11, 5, 1):
2668 case IP_VERSION(11, 5, 2):
2669 adev->flags |= AMD_IS_APU;
2675 if (amdgpu_ip_version(adev, XGMI_HWIP, 0) == IP_VERSION(4, 8, 0))
2676 adev->gmc.xgmi.supported = true;
2678 if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) ||
2679 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 4))
2680 adev->ip_versions[XGMI_HWIP][0] = IP_VERSION(6, 4, 0);
2682 /* set NBIO version */
2683 switch (amdgpu_ip_version(adev, NBIO_HWIP, 0)) {
2684 case IP_VERSION(6, 1, 0):
2685 case IP_VERSION(6, 2, 0):
2686 adev->nbio.funcs = &nbio_v6_1_funcs;
2687 adev->nbio.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg;
2689 case IP_VERSION(7, 0, 0):
2690 case IP_VERSION(7, 0, 1):
2691 case IP_VERSION(2, 5, 0):
2692 adev->nbio.funcs = &nbio_v7_0_funcs;
2693 adev->nbio.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg;
2695 case IP_VERSION(7, 4, 0):
2696 case IP_VERSION(7, 4, 1):
2697 case IP_VERSION(7, 4, 4):
2698 adev->nbio.funcs = &nbio_v7_4_funcs;
2699 adev->nbio.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg;
2701 case IP_VERSION(7, 9, 0):
2702 adev->nbio.funcs = &nbio_v7_9_funcs;
2703 adev->nbio.hdp_flush_reg = &nbio_v7_9_hdp_flush_reg;
2705 case IP_VERSION(7, 11, 0):
2706 case IP_VERSION(7, 11, 1):
2707 case IP_VERSION(7, 11, 3):
2708 adev->nbio.funcs = &nbio_v7_11_funcs;
2709 adev->nbio.hdp_flush_reg = &nbio_v7_11_hdp_flush_reg;
2711 case IP_VERSION(7, 2, 0):
2712 case IP_VERSION(7, 2, 1):
2713 case IP_VERSION(7, 3, 0):
2714 case IP_VERSION(7, 5, 0):
2715 case IP_VERSION(7, 5, 1):
2716 adev->nbio.funcs = &nbio_v7_2_funcs;
2717 adev->nbio.hdp_flush_reg = &nbio_v7_2_hdp_flush_reg;
2719 case IP_VERSION(2, 1, 1):
2720 case IP_VERSION(2, 3, 0):
2721 case IP_VERSION(2, 3, 1):
2722 case IP_VERSION(2, 3, 2):
2723 case IP_VERSION(3, 3, 0):
2724 case IP_VERSION(3, 3, 1):
2725 case IP_VERSION(3, 3, 2):
2726 case IP_VERSION(3, 3, 3):
2727 adev->nbio.funcs = &nbio_v2_3_funcs;
2728 adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg;
2730 case IP_VERSION(4, 3, 0):
2731 case IP_VERSION(4, 3, 1):
2732 if (amdgpu_sriov_vf(adev))
2733 adev->nbio.funcs = &nbio_v4_3_sriov_funcs;
2735 adev->nbio.funcs = &nbio_v4_3_funcs;
2736 adev->nbio.hdp_flush_reg = &nbio_v4_3_hdp_flush_reg;
2738 case IP_VERSION(7, 7, 0):
2739 case IP_VERSION(7, 7, 1):
2740 adev->nbio.funcs = &nbio_v7_7_funcs;
2741 adev->nbio.hdp_flush_reg = &nbio_v7_7_hdp_flush_reg;
2743 case IP_VERSION(6, 3, 1):
2744 adev->nbio.funcs = &nbif_v6_3_1_funcs;
2745 adev->nbio.hdp_flush_reg = &nbif_v6_3_1_hdp_flush_reg;
2751 switch (amdgpu_ip_version(adev, HDP_HWIP, 0)) {
2752 case IP_VERSION(4, 0, 0):
2753 case IP_VERSION(4, 0, 1):
2754 case IP_VERSION(4, 1, 0):
2755 case IP_VERSION(4, 1, 1):
2756 case IP_VERSION(4, 1, 2):
2757 case IP_VERSION(4, 2, 0):
2758 case IP_VERSION(4, 2, 1):
2759 case IP_VERSION(4, 4, 0):
2760 case IP_VERSION(4, 4, 2):
2761 case IP_VERSION(4, 4, 5):
2762 adev->hdp.funcs = &hdp_v4_0_funcs;
2764 case IP_VERSION(5, 0, 0):
2765 case IP_VERSION(5, 0, 1):
2766 case IP_VERSION(5, 0, 2):
2767 case IP_VERSION(5, 0, 3):
2768 case IP_VERSION(5, 0, 4):
2769 case IP_VERSION(5, 2, 0):
2770 adev->hdp.funcs = &hdp_v5_0_funcs;
2772 case IP_VERSION(5, 2, 1):
2773 adev->hdp.funcs = &hdp_v5_2_funcs;
2775 case IP_VERSION(6, 0, 0):
2776 case IP_VERSION(6, 0, 1):
2777 case IP_VERSION(6, 1, 0):
2778 adev->hdp.funcs = &hdp_v6_0_funcs;
2780 case IP_VERSION(7, 0, 0):
2781 adev->hdp.funcs = &hdp_v7_0_funcs;
2787 switch (amdgpu_ip_version(adev, DF_HWIP, 0)) {
2788 case IP_VERSION(3, 6, 0):
2789 case IP_VERSION(3, 6, 1):
2790 case IP_VERSION(3, 6, 2):
2791 adev->df.funcs = &df_v3_6_funcs;
2793 case IP_VERSION(2, 1, 0):
2794 case IP_VERSION(2, 1, 1):
2795 case IP_VERSION(2, 5, 0):
2796 case IP_VERSION(3, 5, 1):
2797 case IP_VERSION(3, 5, 2):
2798 adev->df.funcs = &df_v1_7_funcs;
2800 case IP_VERSION(4, 3, 0):
2801 adev->df.funcs = &df_v4_3_funcs;
2803 case IP_VERSION(4, 6, 2):
2804 adev->df.funcs = &df_v4_6_2_funcs;
2810 switch (amdgpu_ip_version(adev, SMUIO_HWIP, 0)) {
2811 case IP_VERSION(9, 0, 0):
2812 case IP_VERSION(9, 0, 1):
2813 case IP_VERSION(10, 0, 0):
2814 case IP_VERSION(10, 0, 1):
2815 case IP_VERSION(10, 0, 2):
2816 adev->smuio.funcs = &smuio_v9_0_funcs;
2818 case IP_VERSION(11, 0, 0):
2819 case IP_VERSION(11, 0, 2):
2820 case IP_VERSION(11, 0, 3):
2821 case IP_VERSION(11, 0, 4):
2822 case IP_VERSION(11, 0, 7):
2823 case IP_VERSION(11, 0, 8):
2824 adev->smuio.funcs = &smuio_v11_0_funcs;
2826 case IP_VERSION(11, 0, 6):
2827 case IP_VERSION(11, 0, 10):
2828 case IP_VERSION(11, 0, 11):
2829 case IP_VERSION(11, 5, 0):
2830 case IP_VERSION(13, 0, 1):
2831 case IP_VERSION(13, 0, 9):
2832 case IP_VERSION(13, 0, 10):
2833 adev->smuio.funcs = &smuio_v11_0_6_funcs;
2835 case IP_VERSION(13, 0, 2):
2836 adev->smuio.funcs = &smuio_v13_0_funcs;
2838 case IP_VERSION(13, 0, 3):
2839 adev->smuio.funcs = &smuio_v13_0_3_funcs;
2840 if (adev->smuio.funcs->get_pkg_type(adev) == AMDGPU_PKG_TYPE_APU) {
2841 adev->flags |= AMD_IS_APU;
2844 case IP_VERSION(13, 0, 6):
2845 case IP_VERSION(13, 0, 8):
2846 case IP_VERSION(14, 0, 0):
2847 case IP_VERSION(14, 0, 1):
2848 adev->smuio.funcs = &smuio_v13_0_6_funcs;
2850 case IP_VERSION(14, 0, 2):
2851 adev->smuio.funcs = &smuio_v14_0_2_funcs;
2857 switch (amdgpu_ip_version(adev, LSDMA_HWIP, 0)) {
2858 case IP_VERSION(6, 0, 0):
2859 case IP_VERSION(6, 0, 1):
2860 case IP_VERSION(6, 0, 2):
2861 case IP_VERSION(6, 0, 3):
2862 adev->lsdma.funcs = &lsdma_v6_0_funcs;
2864 case IP_VERSION(7, 0, 0):
2865 case IP_VERSION(7, 0, 1):
2866 adev->lsdma.funcs = &lsdma_v7_0_funcs;
2872 r = amdgpu_discovery_set_common_ip_blocks(adev);
2876 r = amdgpu_discovery_set_gmc_ip_blocks(adev);
2880 /* For SR-IOV, PSP needs to be initialized before IH */
2881 if (amdgpu_sriov_vf(adev)) {
2882 r = amdgpu_discovery_set_psp_ip_blocks(adev);
2885 r = amdgpu_discovery_set_ih_ip_blocks(adev);
2889 r = amdgpu_discovery_set_ih_ip_blocks(adev);
2893 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
2894 r = amdgpu_discovery_set_psp_ip_blocks(adev);
2900 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
2901 r = amdgpu_discovery_set_smu_ip_blocks(adev);
2906 r = amdgpu_discovery_set_display_ip_blocks(adev);
2910 r = amdgpu_discovery_set_gc_ip_blocks(adev);
2914 r = amdgpu_discovery_set_sdma_ip_blocks(adev);
2918 if ((adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
2919 !amdgpu_sriov_vf(adev)) ||
2920 (adev->firmware.load_type == AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO && amdgpu_dpm == 1)) {
2921 r = amdgpu_discovery_set_smu_ip_blocks(adev);
2926 r = amdgpu_discovery_set_mm_ip_blocks(adev);
2930 r = amdgpu_discovery_set_mes_ip_blocks(adev);
2934 r = amdgpu_discovery_set_vpe_ip_blocks(adev);
2938 r = amdgpu_discovery_set_umsch_mm_ip_blocks(adev);
2942 r = amdgpu_discovery_set_isp_ip_blocks(adev);