1 /* 2 * Copyright 2018-2024 Advanced Micro Devices, Inc. All rights reserved. 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 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. 21 * 22 */ 23 24 #include <linux/firmware.h> 25 26 #include "amdgpu.h" 27 #include "amdgpu_discovery.h" 28 #include "soc15_hw_ip.h" 29 #include "discovery.h" 30 #include "amdgpu_ras.h" 31 32 #include "soc15.h" 33 #include "gfx_v9_0.h" 34 #include "gfx_v9_4_3.h" 35 #include "gmc_v9_0.h" 36 #include "df_v1_7.h" 37 #include "df_v3_6.h" 38 #include "df_v4_3.h" 39 #include "df_v4_6_2.h" 40 #include "df_v4_15.h" 41 #include "nbio_v6_1.h" 42 #include "nbio_v7_0.h" 43 #include "nbio_v7_4.h" 44 #include "nbio_v7_9.h" 45 #include "nbio_v7_11.h" 46 #include "hdp_v4_0.h" 47 #include "vega10_ih.h" 48 #include "vega20_ih.h" 49 #include "sdma_v4_0.h" 50 #include "sdma_v4_4_2.h" 51 #include "uvd_v7_0.h" 52 #include "vce_v4_0.h" 53 #include "vcn_v1_0.h" 54 #include "vcn_v2_5.h" 55 #include "jpeg_v2_5.h" 56 #include "smuio_v9_0.h" 57 #include "gmc_v10_0.h" 58 #include "gmc_v11_0.h" 59 #include "gmc_v12_0.h" 60 #include "gfxhub_v2_0.h" 61 #include "mmhub_v2_0.h" 62 #include "nbio_v2_3.h" 63 #include "nbio_v4_3.h" 64 #include "nbio_v7_2.h" 65 #include "nbio_v7_7.h" 66 #include "nbif_v6_3_1.h" 67 #include "hdp_v5_0.h" 68 #include "hdp_v5_2.h" 69 #include "hdp_v6_0.h" 70 #include "hdp_v7_0.h" 71 #include "nv.h" 72 #include "soc21.h" 73 #include "soc24.h" 74 #include "navi10_ih.h" 75 #include "ih_v6_0.h" 76 #include "ih_v6_1.h" 77 #include "ih_v7_0.h" 78 #include "gfx_v10_0.h" 79 #include "gfx_v11_0.h" 80 #include "gfx_v12_0.h" 81 #include "sdma_v5_0.h" 82 #include "sdma_v5_2.h" 83 #include "sdma_v6_0.h" 84 #include "sdma_v7_0.h" 85 #include "lsdma_v6_0.h" 86 #include "lsdma_v7_0.h" 87 #include "vcn_v2_0.h" 88 #include "jpeg_v2_0.h" 89 #include "vcn_v3_0.h" 90 #include "jpeg_v3_0.h" 91 #include "vcn_v4_0.h" 92 #include "jpeg_v4_0.h" 93 #include "vcn_v4_0_3.h" 94 #include "jpeg_v4_0_3.h" 95 #include "vcn_v4_0_5.h" 96 #include "jpeg_v4_0_5.h" 97 #include "amdgpu_vkms.h" 98 #include "mes_v11_0.h" 99 #include "mes_v12_0.h" 100 #include "smuio_v11_0.h" 101 #include "smuio_v11_0_6.h" 102 #include "smuio_v13_0.h" 103 #include "smuio_v13_0_3.h" 104 #include "smuio_v13_0_6.h" 105 #include "smuio_v14_0_2.h" 106 #include "vcn_v5_0_0.h" 107 #include "vcn_v5_0_1.h" 108 #include "jpeg_v5_0_0.h" 109 #include "jpeg_v5_0_1.h" 110 111 #include "amdgpu_vpe.h" 112 #if defined(CONFIG_DRM_AMD_ISP) 113 #include "amdgpu_isp.h" 114 #endif 115 116 MODULE_FIRMWARE("amdgpu/ip_discovery.bin"); 117 MODULE_FIRMWARE("amdgpu/vega10_ip_discovery.bin"); 118 MODULE_FIRMWARE("amdgpu/vega12_ip_discovery.bin"); 119 MODULE_FIRMWARE("amdgpu/vega20_ip_discovery.bin"); 120 MODULE_FIRMWARE("amdgpu/raven_ip_discovery.bin"); 121 MODULE_FIRMWARE("amdgpu/raven2_ip_discovery.bin"); 122 MODULE_FIRMWARE("amdgpu/picasso_ip_discovery.bin"); 123 MODULE_FIRMWARE("amdgpu/arcturus_ip_discovery.bin"); 124 MODULE_FIRMWARE("amdgpu/aldebaran_ip_discovery.bin"); 125 126 #define mmIP_DISCOVERY_VERSION 0x16A00 127 #define mmRCC_CONFIG_MEMSIZE 0xde3 128 #define mmMP0_SMN_C2PMSG_33 0x16061 129 #define mmMM_INDEX 0x0 130 #define mmMM_INDEX_HI 0x6 131 #define mmMM_DATA 0x1 132 133 static const char *hw_id_names[HW_ID_MAX] = { 134 [MP1_HWID] = "MP1", 135 [MP2_HWID] = "MP2", 136 [THM_HWID] = "THM", 137 [SMUIO_HWID] = "SMUIO", 138 [FUSE_HWID] = "FUSE", 139 [CLKA_HWID] = "CLKA", 140 [PWR_HWID] = "PWR", 141 [GC_HWID] = "GC", 142 [UVD_HWID] = "UVD", 143 [AUDIO_AZ_HWID] = "AUDIO_AZ", 144 [ACP_HWID] = "ACP", 145 [DCI_HWID] = "DCI", 146 [DMU_HWID] = "DMU", 147 [DCO_HWID] = "DCO", 148 [DIO_HWID] = "DIO", 149 [XDMA_HWID] = "XDMA", 150 [DCEAZ_HWID] = "DCEAZ", 151 [DAZ_HWID] = "DAZ", 152 [SDPMUX_HWID] = "SDPMUX", 153 [NTB_HWID] = "NTB", 154 [IOHC_HWID] = "IOHC", 155 [L2IMU_HWID] = "L2IMU", 156 [VCE_HWID] = "VCE", 157 [MMHUB_HWID] = "MMHUB", 158 [ATHUB_HWID] = "ATHUB", 159 [DBGU_NBIO_HWID] = "DBGU_NBIO", 160 [DFX_HWID] = "DFX", 161 [DBGU0_HWID] = "DBGU0", 162 [DBGU1_HWID] = "DBGU1", 163 [OSSSYS_HWID] = "OSSSYS", 164 [HDP_HWID] = "HDP", 165 [SDMA0_HWID] = "SDMA0", 166 [SDMA1_HWID] = "SDMA1", 167 [SDMA2_HWID] = "SDMA2", 168 [SDMA3_HWID] = "SDMA3", 169 [LSDMA_HWID] = "LSDMA", 170 [ISP_HWID] = "ISP", 171 [DBGU_IO_HWID] = "DBGU_IO", 172 [DF_HWID] = "DF", 173 [CLKB_HWID] = "CLKB", 174 [FCH_HWID] = "FCH", 175 [DFX_DAP_HWID] = "DFX_DAP", 176 [L1IMU_PCIE_HWID] = "L1IMU_PCIE", 177 [L1IMU_NBIF_HWID] = "L1IMU_NBIF", 178 [L1IMU_IOAGR_HWID] = "L1IMU_IOAGR", 179 [L1IMU3_HWID] = "L1IMU3", 180 [L1IMU4_HWID] = "L1IMU4", 181 [L1IMU5_HWID] = "L1IMU5", 182 [L1IMU6_HWID] = "L1IMU6", 183 [L1IMU7_HWID] = "L1IMU7", 184 [L1IMU8_HWID] = "L1IMU8", 185 [L1IMU9_HWID] = "L1IMU9", 186 [L1IMU10_HWID] = "L1IMU10", 187 [L1IMU11_HWID] = "L1IMU11", 188 [L1IMU12_HWID] = "L1IMU12", 189 [L1IMU13_HWID] = "L1IMU13", 190 [L1IMU14_HWID] = "L1IMU14", 191 [L1IMU15_HWID] = "L1IMU15", 192 [WAFLC_HWID] = "WAFLC", 193 [FCH_USB_PD_HWID] = "FCH_USB_PD", 194 [PCIE_HWID] = "PCIE", 195 [PCS_HWID] = "PCS", 196 [DDCL_HWID] = "DDCL", 197 [SST_HWID] = "SST", 198 [IOAGR_HWID] = "IOAGR", 199 [NBIF_HWID] = "NBIF", 200 [IOAPIC_HWID] = "IOAPIC", 201 [SYSTEMHUB_HWID] = "SYSTEMHUB", 202 [NTBCCP_HWID] = "NTBCCP", 203 [UMC_HWID] = "UMC", 204 [SATA_HWID] = "SATA", 205 [USB_HWID] = "USB", 206 [CCXSEC_HWID] = "CCXSEC", 207 [XGMI_HWID] = "XGMI", 208 [XGBE_HWID] = "XGBE", 209 [MP0_HWID] = "MP0", 210 [VPE_HWID] = "VPE", 211 }; 212 213 static int hw_id_map[MAX_HWIP] = { 214 [GC_HWIP] = GC_HWID, 215 [HDP_HWIP] = HDP_HWID, 216 [SDMA0_HWIP] = SDMA0_HWID, 217 [SDMA1_HWIP] = SDMA1_HWID, 218 [SDMA2_HWIP] = SDMA2_HWID, 219 [SDMA3_HWIP] = SDMA3_HWID, 220 [LSDMA_HWIP] = LSDMA_HWID, 221 [MMHUB_HWIP] = MMHUB_HWID, 222 [ATHUB_HWIP] = ATHUB_HWID, 223 [NBIO_HWIP] = NBIF_HWID, 224 [MP0_HWIP] = MP0_HWID, 225 [MP1_HWIP] = MP1_HWID, 226 [UVD_HWIP] = UVD_HWID, 227 [VCE_HWIP] = VCE_HWID, 228 [DF_HWIP] = DF_HWID, 229 [DCE_HWIP] = DMU_HWID, 230 [OSSSYS_HWIP] = OSSSYS_HWID, 231 [SMUIO_HWIP] = SMUIO_HWID, 232 [PWR_HWIP] = PWR_HWID, 233 [NBIF_HWIP] = NBIF_HWID, 234 [THM_HWIP] = THM_HWID, 235 [CLK_HWIP] = CLKA_HWID, 236 [UMC_HWIP] = UMC_HWID, 237 [XGMI_HWIP] = XGMI_HWID, 238 [DCI_HWIP] = DCI_HWID, 239 [PCIE_HWIP] = PCIE_HWID, 240 [VPE_HWIP] = VPE_HWID, 241 [ISP_HWIP] = ISP_HWID, 242 }; 243 244 static int amdgpu_discovery_read_binary_from_sysmem(struct amdgpu_device *adev, uint8_t *binary) 245 { 246 u64 tmr_offset, tmr_size, pos; 247 void *discv_regn; 248 int ret; 249 250 ret = amdgpu_acpi_get_tmr_info(adev, &tmr_offset, &tmr_size); 251 if (ret) 252 return ret; 253 254 pos = tmr_offset + tmr_size - DISCOVERY_TMR_OFFSET; 255 256 /* This region is read-only and reserved from system use */ 257 discv_regn = memremap(pos, adev->mman.discovery_tmr_size, MEMREMAP_WC); 258 if (discv_regn) { 259 memcpy(binary, discv_regn, adev->mman.discovery_tmr_size); 260 memunmap(discv_regn); 261 return 0; 262 } 263 264 return -ENOENT; 265 } 266 267 #define IP_DISCOVERY_V2 2 268 #define IP_DISCOVERY_V4 4 269 270 static int amdgpu_discovery_read_binary_from_mem(struct amdgpu_device *adev, 271 uint8_t *binary) 272 { 273 bool sz_valid = true; 274 uint64_t vram_size; 275 int i, ret = 0; 276 u32 msg; 277 278 if (!amdgpu_sriov_vf(adev)) { 279 /* It can take up to two second for IFWI init to complete on some dGPUs, 280 * but generally it should be in the 60-100ms range. Normally this starts 281 * as soon as the device gets power so by the time the OS loads this has long 282 * completed. However, when a card is hotplugged via e.g., USB4, we need to 283 * wait for this to complete. Once the C2PMSG is updated, we can 284 * continue. 285 */ 286 287 for (i = 0; i < 2000; i++) { 288 msg = RREG32(mmMP0_SMN_C2PMSG_33); 289 if (msg & 0x80000000) 290 break; 291 msleep(1); 292 } 293 } 294 295 vram_size = RREG32(mmRCC_CONFIG_MEMSIZE); 296 if (!vram_size || vram_size == U32_MAX) 297 sz_valid = false; 298 else 299 vram_size <<= 20; 300 301 if (sz_valid) { 302 uint64_t pos = vram_size - DISCOVERY_TMR_OFFSET; 303 amdgpu_device_vram_access(adev, pos, (uint32_t *)binary, 304 adev->mman.discovery_tmr_size, false); 305 } else { 306 ret = amdgpu_discovery_read_binary_from_sysmem(adev, binary); 307 } 308 309 if (ret) 310 dev_err(adev->dev, 311 "failed to read discovery info from memory, vram size read: %llx", 312 vram_size); 313 314 return ret; 315 } 316 317 static int amdgpu_discovery_read_binary_from_file(struct amdgpu_device *adev, 318 uint8_t *binary, 319 const char *fw_name) 320 { 321 const struct firmware *fw; 322 int r; 323 324 r = firmware_request_nowarn(&fw, fw_name, adev->dev); 325 if (r) { 326 if (amdgpu_discovery == 2) 327 dev_err(adev->dev, "can't load firmware \"%s\"\n", fw_name); 328 else 329 drm_info(&adev->ddev, "Optional firmware \"%s\" was not found\n", fw_name); 330 return r; 331 } 332 333 memcpy((u8 *)binary, (u8 *)fw->data, fw->size); 334 release_firmware(fw); 335 336 return 0; 337 } 338 339 static uint16_t amdgpu_discovery_calculate_checksum(uint8_t *data, uint32_t size) 340 { 341 uint16_t checksum = 0; 342 int i; 343 344 for (i = 0; i < size; i++) 345 checksum += data[i]; 346 347 return checksum; 348 } 349 350 static inline bool amdgpu_discovery_verify_checksum(uint8_t *data, uint32_t size, 351 uint16_t expected) 352 { 353 return !!(amdgpu_discovery_calculate_checksum(data, size) == expected); 354 } 355 356 static inline bool amdgpu_discovery_verify_binary_signature(uint8_t *binary) 357 { 358 struct binary_header *bhdr; 359 bhdr = (struct binary_header *)binary; 360 361 return (le32_to_cpu(bhdr->binary_signature) == BINARY_SIGNATURE); 362 } 363 364 static void amdgpu_discovery_harvest_config_quirk(struct amdgpu_device *adev) 365 { 366 /* 367 * So far, apply this quirk only on those Navy Flounder boards which 368 * have a bad harvest table of VCN config. 369 */ 370 if ((amdgpu_ip_version(adev, UVD_HWIP, 1) == IP_VERSION(3, 0, 1)) && 371 (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(10, 3, 2))) { 372 switch (adev->pdev->revision) { 373 case 0xC1: 374 case 0xC2: 375 case 0xC3: 376 case 0xC5: 377 case 0xC7: 378 case 0xCF: 379 case 0xDF: 380 adev->vcn.harvest_config |= AMDGPU_VCN_HARVEST_VCN1; 381 adev->vcn.inst_mask &= ~AMDGPU_VCN_HARVEST_VCN1; 382 break; 383 default: 384 break; 385 } 386 } 387 } 388 389 static int amdgpu_discovery_verify_npsinfo(struct amdgpu_device *adev, 390 struct binary_header *bhdr) 391 { 392 struct table_info *info; 393 uint16_t checksum; 394 uint16_t offset; 395 396 info = &bhdr->table_list[NPS_INFO]; 397 offset = le16_to_cpu(info->offset); 398 checksum = le16_to_cpu(info->checksum); 399 400 struct nps_info_header *nhdr = 401 (struct nps_info_header *)(adev->mman.discovery_bin + offset); 402 403 if (le32_to_cpu(nhdr->table_id) != NPS_INFO_TABLE_ID) { 404 dev_dbg(adev->dev, "invalid ip discovery nps info table id\n"); 405 return -EINVAL; 406 } 407 408 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 409 le32_to_cpu(nhdr->size_bytes), 410 checksum)) { 411 dev_dbg(adev->dev, "invalid nps info data table checksum\n"); 412 return -EINVAL; 413 } 414 415 return 0; 416 } 417 418 static const char *amdgpu_discovery_get_fw_name(struct amdgpu_device *adev) 419 { 420 if (amdgpu_discovery == 2) 421 return "amdgpu/ip_discovery.bin"; 422 423 switch (adev->asic_type) { 424 case CHIP_VEGA10: 425 return "amdgpu/vega10_ip_discovery.bin"; 426 case CHIP_VEGA12: 427 return "amdgpu/vega12_ip_discovery.bin"; 428 case CHIP_RAVEN: 429 if (adev->apu_flags & AMD_APU_IS_RAVEN2) 430 return "amdgpu/raven2_ip_discovery.bin"; 431 else if (adev->apu_flags & AMD_APU_IS_PICASSO) 432 return "amdgpu/picasso_ip_discovery.bin"; 433 else 434 return "amdgpu/raven_ip_discovery.bin"; 435 case CHIP_VEGA20: 436 return "amdgpu/vega20_ip_discovery.bin"; 437 case CHIP_ARCTURUS: 438 return "amdgpu/arcturus_ip_discovery.bin"; 439 case CHIP_ALDEBARAN: 440 return "amdgpu/aldebaran_ip_discovery.bin"; 441 default: 442 return NULL; 443 } 444 } 445 446 static int amdgpu_discovery_init(struct amdgpu_device *adev) 447 { 448 struct table_info *info; 449 struct binary_header *bhdr; 450 const char *fw_name; 451 uint16_t offset; 452 uint16_t size; 453 uint16_t checksum; 454 int r; 455 456 adev->mman.discovery_tmr_size = DISCOVERY_TMR_SIZE; 457 adev->mman.discovery_bin = kzalloc(adev->mman.discovery_tmr_size, GFP_KERNEL); 458 if (!adev->mman.discovery_bin) 459 return -ENOMEM; 460 461 /* Read from file if it is the preferred option */ 462 fw_name = amdgpu_discovery_get_fw_name(adev); 463 if (fw_name != NULL) { 464 drm_dbg(&adev->ddev, "use ip discovery information from file"); 465 r = amdgpu_discovery_read_binary_from_file(adev, adev->mman.discovery_bin, fw_name); 466 if (r) 467 goto out; 468 } else { 469 drm_dbg(&adev->ddev, "use ip discovery information from memory"); 470 r = amdgpu_discovery_read_binary_from_mem( 471 adev, adev->mman.discovery_bin); 472 if (r) 473 goto out; 474 } 475 476 /* check the ip discovery binary signature */ 477 if (!amdgpu_discovery_verify_binary_signature(adev->mman.discovery_bin)) { 478 dev_err(adev->dev, 479 "get invalid ip discovery binary signature\n"); 480 r = -EINVAL; 481 goto out; 482 } 483 484 bhdr = (struct binary_header *)adev->mman.discovery_bin; 485 486 offset = offsetof(struct binary_header, binary_checksum) + 487 sizeof(bhdr->binary_checksum); 488 size = le16_to_cpu(bhdr->binary_size) - offset; 489 checksum = le16_to_cpu(bhdr->binary_checksum); 490 491 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 492 size, checksum)) { 493 dev_err(adev->dev, "invalid ip discovery binary checksum\n"); 494 r = -EINVAL; 495 goto out; 496 } 497 498 info = &bhdr->table_list[IP_DISCOVERY]; 499 offset = le16_to_cpu(info->offset); 500 checksum = le16_to_cpu(info->checksum); 501 502 if (offset) { 503 struct ip_discovery_header *ihdr = 504 (struct ip_discovery_header *)(adev->mman.discovery_bin + offset); 505 if (le32_to_cpu(ihdr->signature) != DISCOVERY_TABLE_SIGNATURE) { 506 dev_err(adev->dev, "invalid ip discovery data table signature\n"); 507 r = -EINVAL; 508 goto out; 509 } 510 511 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 512 le16_to_cpu(ihdr->size), checksum)) { 513 dev_err(adev->dev, "invalid ip discovery data table checksum\n"); 514 r = -EINVAL; 515 goto out; 516 } 517 } 518 519 info = &bhdr->table_list[GC]; 520 offset = le16_to_cpu(info->offset); 521 checksum = le16_to_cpu(info->checksum); 522 523 if (offset) { 524 struct gpu_info_header *ghdr = 525 (struct gpu_info_header *)(adev->mman.discovery_bin + offset); 526 527 if (le32_to_cpu(ghdr->table_id) != GC_TABLE_ID) { 528 dev_err(adev->dev, "invalid ip discovery gc table id\n"); 529 r = -EINVAL; 530 goto out; 531 } 532 533 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 534 le32_to_cpu(ghdr->size), checksum)) { 535 dev_err(adev->dev, "invalid gc data table checksum\n"); 536 r = -EINVAL; 537 goto out; 538 } 539 } 540 541 info = &bhdr->table_list[HARVEST_INFO]; 542 offset = le16_to_cpu(info->offset); 543 checksum = le16_to_cpu(info->checksum); 544 545 if (offset) { 546 struct harvest_info_header *hhdr = 547 (struct harvest_info_header *)(adev->mman.discovery_bin + offset); 548 549 if (le32_to_cpu(hhdr->signature) != HARVEST_TABLE_SIGNATURE) { 550 dev_err(adev->dev, "invalid ip discovery harvest table signature\n"); 551 r = -EINVAL; 552 goto out; 553 } 554 555 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 556 sizeof(struct harvest_table), checksum)) { 557 dev_err(adev->dev, "invalid harvest data table checksum\n"); 558 r = -EINVAL; 559 goto out; 560 } 561 } 562 563 info = &bhdr->table_list[VCN_INFO]; 564 offset = le16_to_cpu(info->offset); 565 checksum = le16_to_cpu(info->checksum); 566 567 if (offset) { 568 struct vcn_info_header *vhdr = 569 (struct vcn_info_header *)(adev->mman.discovery_bin + offset); 570 571 if (le32_to_cpu(vhdr->table_id) != VCN_INFO_TABLE_ID) { 572 dev_err(adev->dev, "invalid ip discovery vcn table id\n"); 573 r = -EINVAL; 574 goto out; 575 } 576 577 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 578 le32_to_cpu(vhdr->size_bytes), checksum)) { 579 dev_err(adev->dev, "invalid vcn data table checksum\n"); 580 r = -EINVAL; 581 goto out; 582 } 583 } 584 585 info = &bhdr->table_list[MALL_INFO]; 586 offset = le16_to_cpu(info->offset); 587 checksum = le16_to_cpu(info->checksum); 588 589 if (0 && offset) { 590 struct mall_info_header *mhdr = 591 (struct mall_info_header *)(adev->mman.discovery_bin + offset); 592 593 if (le32_to_cpu(mhdr->table_id) != MALL_INFO_TABLE_ID) { 594 dev_err(adev->dev, "invalid ip discovery mall table id\n"); 595 r = -EINVAL; 596 goto out; 597 } 598 599 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 600 le32_to_cpu(mhdr->size_bytes), checksum)) { 601 dev_err(adev->dev, "invalid mall data table checksum\n"); 602 r = -EINVAL; 603 goto out; 604 } 605 } 606 607 return 0; 608 609 out: 610 kfree(adev->mman.discovery_bin); 611 adev->mman.discovery_bin = NULL; 612 if ((amdgpu_discovery != 2) && 613 (RREG32(mmIP_DISCOVERY_VERSION) == 4)) 614 amdgpu_ras_query_boot_status(adev, 4); 615 return r; 616 } 617 618 static void amdgpu_discovery_sysfs_fini(struct amdgpu_device *adev); 619 620 void amdgpu_discovery_fini(struct amdgpu_device *adev) 621 { 622 amdgpu_discovery_sysfs_fini(adev); 623 kfree(adev->mman.discovery_bin); 624 adev->mman.discovery_bin = NULL; 625 } 626 627 static int amdgpu_discovery_validate_ip(struct amdgpu_device *adev, 628 uint8_t instance, uint16_t hw_id) 629 { 630 if (instance >= HWIP_MAX_INSTANCE) { 631 dev_err(adev->dev, 632 "Unexpected instance_number (%d) from ip discovery blob\n", 633 instance); 634 return -EINVAL; 635 } 636 if (hw_id >= HW_ID_MAX) { 637 dev_err(adev->dev, 638 "Unexpected hw_id (%d) from ip discovery blob\n", 639 hw_id); 640 return -EINVAL; 641 } 642 643 return 0; 644 } 645 646 static void amdgpu_discovery_read_harvest_bit_per_ip(struct amdgpu_device *adev, 647 uint32_t *vcn_harvest_count) 648 { 649 struct binary_header *bhdr; 650 struct ip_discovery_header *ihdr; 651 struct die_header *dhdr; 652 struct ip *ip; 653 uint16_t die_offset, ip_offset, num_dies, num_ips; 654 uint16_t hw_id; 655 uint8_t inst; 656 int i, j; 657 658 bhdr = (struct binary_header *)adev->mman.discovery_bin; 659 ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin + 660 le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset)); 661 num_dies = le16_to_cpu(ihdr->num_dies); 662 663 /* scan harvest bit of all IP data structures */ 664 for (i = 0; i < num_dies; i++) { 665 die_offset = le16_to_cpu(ihdr->die_info[i].die_offset); 666 dhdr = (struct die_header *)(adev->mman.discovery_bin + die_offset); 667 num_ips = le16_to_cpu(dhdr->num_ips); 668 ip_offset = die_offset + sizeof(*dhdr); 669 670 for (j = 0; j < num_ips; j++) { 671 ip = (struct ip *)(adev->mman.discovery_bin + 672 ip_offset); 673 inst = ip->number_instance; 674 hw_id = le16_to_cpu(ip->hw_id); 675 if (amdgpu_discovery_validate_ip(adev, inst, hw_id)) 676 goto next_ip; 677 678 if (ip->harvest == 1) { 679 switch (hw_id) { 680 case VCN_HWID: 681 (*vcn_harvest_count)++; 682 if (inst == 0) { 683 adev->vcn.harvest_config |= AMDGPU_VCN_HARVEST_VCN0; 684 adev->vcn.inst_mask &= 685 ~AMDGPU_VCN_HARVEST_VCN0; 686 adev->jpeg.inst_mask &= 687 ~AMDGPU_VCN_HARVEST_VCN0; 688 } else { 689 adev->vcn.harvest_config |= AMDGPU_VCN_HARVEST_VCN1; 690 adev->vcn.inst_mask &= 691 ~AMDGPU_VCN_HARVEST_VCN1; 692 adev->jpeg.inst_mask &= 693 ~AMDGPU_VCN_HARVEST_VCN1; 694 } 695 break; 696 case DMU_HWID: 697 adev->harvest_ip_mask |= AMD_HARVEST_IP_DMU_MASK; 698 break; 699 default: 700 break; 701 } 702 } 703 next_ip: 704 ip_offset += struct_size(ip, base_address, 705 ip->num_base_address); 706 } 707 } 708 } 709 710 static void amdgpu_discovery_read_from_harvest_table(struct amdgpu_device *adev, 711 uint32_t *vcn_harvest_count, 712 uint32_t *umc_harvest_count) 713 { 714 struct binary_header *bhdr; 715 struct harvest_table *harvest_info; 716 u16 offset; 717 int i; 718 uint32_t umc_harvest_config = 0; 719 720 bhdr = (struct binary_header *)adev->mman.discovery_bin; 721 offset = le16_to_cpu(bhdr->table_list[HARVEST_INFO].offset); 722 723 if (!offset) { 724 dev_err(adev->dev, "invalid harvest table offset\n"); 725 return; 726 } 727 728 harvest_info = (struct harvest_table *)(adev->mman.discovery_bin + offset); 729 730 for (i = 0; i < 32; i++) { 731 if (le16_to_cpu(harvest_info->list[i].hw_id) == 0) 732 break; 733 734 switch (le16_to_cpu(harvest_info->list[i].hw_id)) { 735 case VCN_HWID: 736 (*vcn_harvest_count)++; 737 adev->vcn.harvest_config |= 738 (1 << harvest_info->list[i].number_instance); 739 adev->jpeg.harvest_config |= 740 (1 << harvest_info->list[i].number_instance); 741 742 adev->vcn.inst_mask &= 743 ~(1U << harvest_info->list[i].number_instance); 744 adev->jpeg.inst_mask &= 745 ~(1U << harvest_info->list[i].number_instance); 746 break; 747 case DMU_HWID: 748 adev->harvest_ip_mask |= AMD_HARVEST_IP_DMU_MASK; 749 break; 750 case UMC_HWID: 751 umc_harvest_config |= 752 1 << (le16_to_cpu(harvest_info->list[i].number_instance)); 753 (*umc_harvest_count)++; 754 break; 755 case GC_HWID: 756 adev->gfx.xcc_mask &= 757 ~(1U << harvest_info->list[i].number_instance); 758 break; 759 case SDMA0_HWID: 760 adev->sdma.sdma_mask &= 761 ~(1U << harvest_info->list[i].number_instance); 762 break; 763 #if defined(CONFIG_DRM_AMD_ISP) 764 case ISP_HWID: 765 adev->isp.harvest_config |= 766 ~(1U << harvest_info->list[i].number_instance); 767 break; 768 #endif 769 default: 770 break; 771 } 772 } 773 774 adev->umc.active_mask = ((1 << adev->umc.node_inst_num) - 1) & 775 ~umc_harvest_config; 776 } 777 778 /* ================================================== */ 779 780 struct ip_hw_instance { 781 struct kobject kobj; /* ip_discovery/die/#die/#hw_id/#instance/<attrs...> */ 782 783 int hw_id; 784 u8 num_instance; 785 u8 major, minor, revision; 786 u8 harvest; 787 788 int num_base_addresses; 789 u32 base_addr[] __counted_by(num_base_addresses); 790 }; 791 792 struct ip_hw_id { 793 struct kset hw_id_kset; /* ip_discovery/die/#die/#hw_id/, contains ip_hw_instance */ 794 int hw_id; 795 }; 796 797 struct ip_die_entry { 798 struct kset ip_kset; /* ip_discovery/die/#die/, contains ip_hw_id */ 799 u16 num_ips; 800 }; 801 802 /* -------------------------------------------------- */ 803 804 struct ip_hw_instance_attr { 805 struct attribute attr; 806 ssize_t (*show)(struct ip_hw_instance *ip_hw_instance, char *buf); 807 }; 808 809 static ssize_t hw_id_show(struct ip_hw_instance *ip_hw_instance, char *buf) 810 { 811 return sysfs_emit(buf, "%d\n", ip_hw_instance->hw_id); 812 } 813 814 static ssize_t num_instance_show(struct ip_hw_instance *ip_hw_instance, char *buf) 815 { 816 return sysfs_emit(buf, "%d\n", ip_hw_instance->num_instance); 817 } 818 819 static ssize_t major_show(struct ip_hw_instance *ip_hw_instance, char *buf) 820 { 821 return sysfs_emit(buf, "%d\n", ip_hw_instance->major); 822 } 823 824 static ssize_t minor_show(struct ip_hw_instance *ip_hw_instance, char *buf) 825 { 826 return sysfs_emit(buf, "%d\n", ip_hw_instance->minor); 827 } 828 829 static ssize_t revision_show(struct ip_hw_instance *ip_hw_instance, char *buf) 830 { 831 return sysfs_emit(buf, "%d\n", ip_hw_instance->revision); 832 } 833 834 static ssize_t harvest_show(struct ip_hw_instance *ip_hw_instance, char *buf) 835 { 836 return sysfs_emit(buf, "0x%01X\n", ip_hw_instance->harvest); 837 } 838 839 static ssize_t num_base_addresses_show(struct ip_hw_instance *ip_hw_instance, char *buf) 840 { 841 return sysfs_emit(buf, "%d\n", ip_hw_instance->num_base_addresses); 842 } 843 844 static ssize_t base_addr_show(struct ip_hw_instance *ip_hw_instance, char *buf) 845 { 846 ssize_t res, at; 847 int ii; 848 849 for (res = at = ii = 0; ii < ip_hw_instance->num_base_addresses; ii++) { 850 /* Here we satisfy the condition that, at + size <= PAGE_SIZE. 851 */ 852 if (at + 12 > PAGE_SIZE) 853 break; 854 res = sysfs_emit_at(buf, at, "0x%08X\n", 855 ip_hw_instance->base_addr[ii]); 856 if (res <= 0) 857 break; 858 at += res; 859 } 860 861 return res < 0 ? res : at; 862 } 863 864 static struct ip_hw_instance_attr ip_hw_attr[] = { 865 __ATTR_RO(hw_id), 866 __ATTR_RO(num_instance), 867 __ATTR_RO(major), 868 __ATTR_RO(minor), 869 __ATTR_RO(revision), 870 __ATTR_RO(harvest), 871 __ATTR_RO(num_base_addresses), 872 __ATTR_RO(base_addr), 873 }; 874 875 static struct attribute *ip_hw_instance_attrs[ARRAY_SIZE(ip_hw_attr) + 1]; 876 ATTRIBUTE_GROUPS(ip_hw_instance); 877 878 #define to_ip_hw_instance(x) container_of(x, struct ip_hw_instance, kobj) 879 #define to_ip_hw_instance_attr(x) container_of(x, struct ip_hw_instance_attr, attr) 880 881 static ssize_t ip_hw_instance_attr_show(struct kobject *kobj, 882 struct attribute *attr, 883 char *buf) 884 { 885 struct ip_hw_instance *ip_hw_instance = to_ip_hw_instance(kobj); 886 struct ip_hw_instance_attr *ip_hw_attr = to_ip_hw_instance_attr(attr); 887 888 if (!ip_hw_attr->show) 889 return -EIO; 890 891 return ip_hw_attr->show(ip_hw_instance, buf); 892 } 893 894 static const struct sysfs_ops ip_hw_instance_sysfs_ops = { 895 .show = ip_hw_instance_attr_show, 896 }; 897 898 static void ip_hw_instance_release(struct kobject *kobj) 899 { 900 struct ip_hw_instance *ip_hw_instance = to_ip_hw_instance(kobj); 901 902 kfree(ip_hw_instance); 903 } 904 905 static const struct kobj_type ip_hw_instance_ktype = { 906 .release = ip_hw_instance_release, 907 .sysfs_ops = &ip_hw_instance_sysfs_ops, 908 .default_groups = ip_hw_instance_groups, 909 }; 910 911 /* -------------------------------------------------- */ 912 913 #define to_ip_hw_id(x) container_of(to_kset(x), struct ip_hw_id, hw_id_kset) 914 915 static void ip_hw_id_release(struct kobject *kobj) 916 { 917 struct ip_hw_id *ip_hw_id = to_ip_hw_id(kobj); 918 919 if (!list_empty(&ip_hw_id->hw_id_kset.list)) 920 DRM_ERROR("ip_hw_id->hw_id_kset is not empty"); 921 kfree(ip_hw_id); 922 } 923 924 static const struct kobj_type ip_hw_id_ktype = { 925 .release = ip_hw_id_release, 926 .sysfs_ops = &kobj_sysfs_ops, 927 }; 928 929 /* -------------------------------------------------- */ 930 931 static void die_kobj_release(struct kobject *kobj); 932 static void ip_disc_release(struct kobject *kobj); 933 934 struct ip_die_entry_attribute { 935 struct attribute attr; 936 ssize_t (*show)(struct ip_die_entry *ip_die_entry, char *buf); 937 }; 938 939 #define to_ip_die_entry_attr(x) container_of(x, struct ip_die_entry_attribute, attr) 940 941 static ssize_t num_ips_show(struct ip_die_entry *ip_die_entry, char *buf) 942 { 943 return sysfs_emit(buf, "%d\n", ip_die_entry->num_ips); 944 } 945 946 /* If there are more ip_die_entry attrs, other than the number of IPs, 947 * we can make this intro an array of attrs, and then initialize 948 * ip_die_entry_attrs in a loop. 949 */ 950 static struct ip_die_entry_attribute num_ips_attr = 951 __ATTR_RO(num_ips); 952 953 static struct attribute *ip_die_entry_attrs[] = { 954 &num_ips_attr.attr, 955 NULL, 956 }; 957 ATTRIBUTE_GROUPS(ip_die_entry); /* ip_die_entry_groups */ 958 959 #define to_ip_die_entry(x) container_of(to_kset(x), struct ip_die_entry, ip_kset) 960 961 static ssize_t ip_die_entry_attr_show(struct kobject *kobj, 962 struct attribute *attr, 963 char *buf) 964 { 965 struct ip_die_entry_attribute *ip_die_entry_attr = to_ip_die_entry_attr(attr); 966 struct ip_die_entry *ip_die_entry = to_ip_die_entry(kobj); 967 968 if (!ip_die_entry_attr->show) 969 return -EIO; 970 971 return ip_die_entry_attr->show(ip_die_entry, buf); 972 } 973 974 static void ip_die_entry_release(struct kobject *kobj) 975 { 976 struct ip_die_entry *ip_die_entry = to_ip_die_entry(kobj); 977 978 if (!list_empty(&ip_die_entry->ip_kset.list)) 979 DRM_ERROR("ip_die_entry->ip_kset is not empty"); 980 kfree(ip_die_entry); 981 } 982 983 static const struct sysfs_ops ip_die_entry_sysfs_ops = { 984 .show = ip_die_entry_attr_show, 985 }; 986 987 static const struct kobj_type ip_die_entry_ktype = { 988 .release = ip_die_entry_release, 989 .sysfs_ops = &ip_die_entry_sysfs_ops, 990 .default_groups = ip_die_entry_groups, 991 }; 992 993 static const struct kobj_type die_kobj_ktype = { 994 .release = die_kobj_release, 995 .sysfs_ops = &kobj_sysfs_ops, 996 }; 997 998 static const struct kobj_type ip_discovery_ktype = { 999 .release = ip_disc_release, 1000 .sysfs_ops = &kobj_sysfs_ops, 1001 }; 1002 1003 struct ip_discovery_top { 1004 struct kobject kobj; /* ip_discovery/ */ 1005 struct kset die_kset; /* ip_discovery/die/, contains ip_die_entry */ 1006 struct amdgpu_device *adev; 1007 }; 1008 1009 static void die_kobj_release(struct kobject *kobj) 1010 { 1011 struct ip_discovery_top *ip_top = container_of(to_kset(kobj), 1012 struct ip_discovery_top, 1013 die_kset); 1014 if (!list_empty(&ip_top->die_kset.list)) 1015 DRM_ERROR("ip_top->die_kset is not empty"); 1016 } 1017 1018 static void ip_disc_release(struct kobject *kobj) 1019 { 1020 struct ip_discovery_top *ip_top = container_of(kobj, struct ip_discovery_top, 1021 kobj); 1022 struct amdgpu_device *adev = ip_top->adev; 1023 1024 adev->ip_top = NULL; 1025 kfree(ip_top); 1026 } 1027 1028 static uint8_t amdgpu_discovery_get_harvest_info(struct amdgpu_device *adev, 1029 uint16_t hw_id, uint8_t inst) 1030 { 1031 uint8_t harvest = 0; 1032 1033 /* Until a uniform way is figured, get mask based on hwid */ 1034 switch (hw_id) { 1035 case VCN_HWID: 1036 harvest = ((1 << inst) & adev->vcn.inst_mask) == 0; 1037 break; 1038 case DMU_HWID: 1039 if (adev->harvest_ip_mask & AMD_HARVEST_IP_DMU_MASK) 1040 harvest = 0x1; 1041 break; 1042 case UMC_HWID: 1043 /* TODO: It needs another parsing; for now, ignore.*/ 1044 break; 1045 case GC_HWID: 1046 harvest = ((1 << inst) & adev->gfx.xcc_mask) == 0; 1047 break; 1048 case SDMA0_HWID: 1049 harvest = ((1 << inst) & adev->sdma.sdma_mask) == 0; 1050 break; 1051 default: 1052 break; 1053 } 1054 1055 return harvest; 1056 } 1057 1058 static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev, 1059 struct ip_die_entry *ip_die_entry, 1060 const size_t _ip_offset, const int num_ips, 1061 bool reg_base_64) 1062 { 1063 int ii, jj, kk, res; 1064 uint16_t hw_id; 1065 uint8_t inst; 1066 1067 DRM_DEBUG("num_ips:%d", num_ips); 1068 1069 /* Find all IPs of a given HW ID, and add their instance to 1070 * #die/#hw_id/#instance/<attributes> 1071 */ 1072 for (ii = 0; ii < HW_ID_MAX; ii++) { 1073 struct ip_hw_id *ip_hw_id = NULL; 1074 size_t ip_offset = _ip_offset; 1075 1076 for (jj = 0; jj < num_ips; jj++) { 1077 struct ip_v4 *ip; 1078 struct ip_hw_instance *ip_hw_instance; 1079 1080 ip = (struct ip_v4 *)(adev->mman.discovery_bin + ip_offset); 1081 inst = ip->instance_number; 1082 hw_id = le16_to_cpu(ip->hw_id); 1083 if (amdgpu_discovery_validate_ip(adev, inst, hw_id) || 1084 hw_id != ii) 1085 goto next_ip; 1086 1087 DRM_DEBUG("match:%d @ ip_offset:%zu", ii, ip_offset); 1088 1089 /* We have a hw_id match; register the hw 1090 * block if not yet registered. 1091 */ 1092 if (!ip_hw_id) { 1093 ip_hw_id = kzalloc(sizeof(*ip_hw_id), GFP_KERNEL); 1094 if (!ip_hw_id) 1095 return -ENOMEM; 1096 ip_hw_id->hw_id = ii; 1097 1098 kobject_set_name(&ip_hw_id->hw_id_kset.kobj, "%d", ii); 1099 ip_hw_id->hw_id_kset.kobj.kset = &ip_die_entry->ip_kset; 1100 ip_hw_id->hw_id_kset.kobj.ktype = &ip_hw_id_ktype; 1101 res = kset_register(&ip_hw_id->hw_id_kset); 1102 if (res) { 1103 DRM_ERROR("Couldn't register ip_hw_id kset"); 1104 kfree(ip_hw_id); 1105 return res; 1106 } 1107 if (hw_id_names[ii]) { 1108 res = sysfs_create_link(&ip_die_entry->ip_kset.kobj, 1109 &ip_hw_id->hw_id_kset.kobj, 1110 hw_id_names[ii]); 1111 if (res) { 1112 DRM_ERROR("Couldn't create IP link %s in IP Die:%s\n", 1113 hw_id_names[ii], 1114 kobject_name(&ip_die_entry->ip_kset.kobj)); 1115 } 1116 } 1117 } 1118 1119 /* Now register its instance. 1120 */ 1121 ip_hw_instance = kzalloc(struct_size(ip_hw_instance, 1122 base_addr, 1123 ip->num_base_address), 1124 GFP_KERNEL); 1125 if (!ip_hw_instance) { 1126 DRM_ERROR("no memory for ip_hw_instance"); 1127 return -ENOMEM; 1128 } 1129 ip_hw_instance->hw_id = le16_to_cpu(ip->hw_id); /* == ii */ 1130 ip_hw_instance->num_instance = ip->instance_number; 1131 ip_hw_instance->major = ip->major; 1132 ip_hw_instance->minor = ip->minor; 1133 ip_hw_instance->revision = ip->revision; 1134 ip_hw_instance->harvest = 1135 amdgpu_discovery_get_harvest_info( 1136 adev, ip_hw_instance->hw_id, 1137 ip_hw_instance->num_instance); 1138 ip_hw_instance->num_base_addresses = ip->num_base_address; 1139 1140 for (kk = 0; kk < ip_hw_instance->num_base_addresses; kk++) { 1141 if (reg_base_64) 1142 ip_hw_instance->base_addr[kk] = 1143 lower_32_bits(le64_to_cpu(ip->base_address_64[kk])) & 0x3FFFFFFF; 1144 else 1145 ip_hw_instance->base_addr[kk] = ip->base_address[kk]; 1146 } 1147 1148 kobject_init(&ip_hw_instance->kobj, &ip_hw_instance_ktype); 1149 ip_hw_instance->kobj.kset = &ip_hw_id->hw_id_kset; 1150 res = kobject_add(&ip_hw_instance->kobj, NULL, 1151 "%d", ip_hw_instance->num_instance); 1152 next_ip: 1153 if (reg_base_64) 1154 ip_offset += struct_size(ip, base_address_64, 1155 ip->num_base_address); 1156 else 1157 ip_offset += struct_size(ip, base_address, 1158 ip->num_base_address); 1159 } 1160 } 1161 1162 return 0; 1163 } 1164 1165 static int amdgpu_discovery_sysfs_recurse(struct amdgpu_device *adev) 1166 { 1167 struct binary_header *bhdr; 1168 struct ip_discovery_header *ihdr; 1169 struct die_header *dhdr; 1170 struct kset *die_kset = &adev->ip_top->die_kset; 1171 u16 num_dies, die_offset, num_ips; 1172 size_t ip_offset; 1173 int ii, res; 1174 1175 bhdr = (struct binary_header *)adev->mman.discovery_bin; 1176 ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin + 1177 le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset)); 1178 num_dies = le16_to_cpu(ihdr->num_dies); 1179 1180 DRM_DEBUG("number of dies: %d\n", num_dies); 1181 1182 for (ii = 0; ii < num_dies; ii++) { 1183 struct ip_die_entry *ip_die_entry; 1184 1185 die_offset = le16_to_cpu(ihdr->die_info[ii].die_offset); 1186 dhdr = (struct die_header *)(adev->mman.discovery_bin + die_offset); 1187 num_ips = le16_to_cpu(dhdr->num_ips); 1188 ip_offset = die_offset + sizeof(*dhdr); 1189 1190 /* Add the die to the kset. 1191 * 1192 * dhdr->die_id == ii, which was checked in 1193 * amdgpu_discovery_reg_base_init(). 1194 */ 1195 1196 ip_die_entry = kzalloc(sizeof(*ip_die_entry), GFP_KERNEL); 1197 if (!ip_die_entry) 1198 return -ENOMEM; 1199 1200 ip_die_entry->num_ips = num_ips; 1201 1202 kobject_set_name(&ip_die_entry->ip_kset.kobj, "%d", le16_to_cpu(dhdr->die_id)); 1203 ip_die_entry->ip_kset.kobj.kset = die_kset; 1204 ip_die_entry->ip_kset.kobj.ktype = &ip_die_entry_ktype; 1205 res = kset_register(&ip_die_entry->ip_kset); 1206 if (res) { 1207 DRM_ERROR("Couldn't register ip_die_entry kset"); 1208 kfree(ip_die_entry); 1209 return res; 1210 } 1211 1212 amdgpu_discovery_sysfs_ips(adev, ip_die_entry, ip_offset, num_ips, !!ihdr->base_addr_64_bit); 1213 } 1214 1215 return 0; 1216 } 1217 1218 static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev) 1219 { 1220 struct kset *die_kset; 1221 int res, ii; 1222 1223 if (!adev->mman.discovery_bin) 1224 return -EINVAL; 1225 1226 adev->ip_top = kzalloc(sizeof(*adev->ip_top), GFP_KERNEL); 1227 if (!adev->ip_top) 1228 return -ENOMEM; 1229 1230 adev->ip_top->adev = adev; 1231 1232 res = kobject_init_and_add(&adev->ip_top->kobj, &ip_discovery_ktype, 1233 &adev->dev->kobj, "ip_discovery"); 1234 if (res) { 1235 DRM_ERROR("Couldn't init and add ip_discovery/"); 1236 goto Err; 1237 } 1238 1239 die_kset = &adev->ip_top->die_kset; 1240 kobject_set_name(&die_kset->kobj, "%s", "die"); 1241 die_kset->kobj.parent = &adev->ip_top->kobj; 1242 die_kset->kobj.ktype = &die_kobj_ktype; 1243 res = kset_register(&adev->ip_top->die_kset); 1244 if (res) { 1245 DRM_ERROR("Couldn't register die_kset"); 1246 goto Err; 1247 } 1248 1249 for (ii = 0; ii < ARRAY_SIZE(ip_hw_attr); ii++) 1250 ip_hw_instance_attrs[ii] = &ip_hw_attr[ii].attr; 1251 ip_hw_instance_attrs[ii] = NULL; 1252 1253 res = amdgpu_discovery_sysfs_recurse(adev); 1254 1255 return res; 1256 Err: 1257 kobject_put(&adev->ip_top->kobj); 1258 return res; 1259 } 1260 1261 /* -------------------------------------------------- */ 1262 1263 #define list_to_kobj(el) container_of(el, struct kobject, entry) 1264 1265 static void amdgpu_discovery_sysfs_ip_hw_free(struct ip_hw_id *ip_hw_id) 1266 { 1267 struct list_head *el, *tmp; 1268 struct kset *hw_id_kset; 1269 1270 hw_id_kset = &ip_hw_id->hw_id_kset; 1271 spin_lock(&hw_id_kset->list_lock); 1272 list_for_each_prev_safe(el, tmp, &hw_id_kset->list) { 1273 list_del_init(el); 1274 spin_unlock(&hw_id_kset->list_lock); 1275 /* kobject is embedded in ip_hw_instance */ 1276 kobject_put(list_to_kobj(el)); 1277 spin_lock(&hw_id_kset->list_lock); 1278 } 1279 spin_unlock(&hw_id_kset->list_lock); 1280 kobject_put(&ip_hw_id->hw_id_kset.kobj); 1281 } 1282 1283 static void amdgpu_discovery_sysfs_die_free(struct ip_die_entry *ip_die_entry) 1284 { 1285 struct list_head *el, *tmp; 1286 struct kset *ip_kset; 1287 1288 ip_kset = &ip_die_entry->ip_kset; 1289 spin_lock(&ip_kset->list_lock); 1290 list_for_each_prev_safe(el, tmp, &ip_kset->list) { 1291 list_del_init(el); 1292 spin_unlock(&ip_kset->list_lock); 1293 amdgpu_discovery_sysfs_ip_hw_free(to_ip_hw_id(list_to_kobj(el))); 1294 spin_lock(&ip_kset->list_lock); 1295 } 1296 spin_unlock(&ip_kset->list_lock); 1297 kobject_put(&ip_die_entry->ip_kset.kobj); 1298 } 1299 1300 static void amdgpu_discovery_sysfs_fini(struct amdgpu_device *adev) 1301 { 1302 struct list_head *el, *tmp; 1303 struct kset *die_kset; 1304 1305 die_kset = &adev->ip_top->die_kset; 1306 spin_lock(&die_kset->list_lock); 1307 list_for_each_prev_safe(el, tmp, &die_kset->list) { 1308 list_del_init(el); 1309 spin_unlock(&die_kset->list_lock); 1310 amdgpu_discovery_sysfs_die_free(to_ip_die_entry(list_to_kobj(el))); 1311 spin_lock(&die_kset->list_lock); 1312 } 1313 spin_unlock(&die_kset->list_lock); 1314 kobject_put(&adev->ip_top->die_kset.kobj); 1315 kobject_put(&adev->ip_top->kobj); 1316 } 1317 1318 /* ================================================== */ 1319 1320 static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev) 1321 { 1322 uint8_t num_base_address, subrev, variant; 1323 struct binary_header *bhdr; 1324 struct ip_discovery_header *ihdr; 1325 struct die_header *dhdr; 1326 struct ip_v4 *ip; 1327 uint16_t die_offset; 1328 uint16_t ip_offset; 1329 uint16_t num_dies; 1330 uint32_t wafl_ver; 1331 uint16_t num_ips; 1332 uint16_t hw_id; 1333 uint8_t inst; 1334 int hw_ip; 1335 int i, j, k; 1336 int r; 1337 1338 r = amdgpu_discovery_init(adev); 1339 if (r) 1340 return r; 1341 1342 wafl_ver = 0; 1343 adev->gfx.xcc_mask = 0; 1344 adev->sdma.sdma_mask = 0; 1345 adev->vcn.inst_mask = 0; 1346 adev->jpeg.inst_mask = 0; 1347 bhdr = (struct binary_header *)adev->mman.discovery_bin; 1348 ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin + 1349 le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset)); 1350 num_dies = le16_to_cpu(ihdr->num_dies); 1351 1352 DRM_DEBUG("number of dies: %d\n", num_dies); 1353 1354 for (i = 0; i < num_dies; i++) { 1355 die_offset = le16_to_cpu(ihdr->die_info[i].die_offset); 1356 dhdr = (struct die_header *)(adev->mman.discovery_bin + die_offset); 1357 num_ips = le16_to_cpu(dhdr->num_ips); 1358 ip_offset = die_offset + sizeof(*dhdr); 1359 1360 if (le16_to_cpu(dhdr->die_id) != i) { 1361 DRM_ERROR("invalid die id %d, expected %d\n", 1362 le16_to_cpu(dhdr->die_id), i); 1363 return -EINVAL; 1364 } 1365 1366 DRM_DEBUG("number of hardware IPs on die%d: %d\n", 1367 le16_to_cpu(dhdr->die_id), num_ips); 1368 1369 for (j = 0; j < num_ips; j++) { 1370 ip = (struct ip_v4 *)(adev->mman.discovery_bin + ip_offset); 1371 1372 inst = ip->instance_number; 1373 hw_id = le16_to_cpu(ip->hw_id); 1374 if (amdgpu_discovery_validate_ip(adev, inst, hw_id)) 1375 goto next_ip; 1376 1377 num_base_address = ip->num_base_address; 1378 1379 DRM_DEBUG("%s(%d) #%d v%d.%d.%d:\n", 1380 hw_id_names[le16_to_cpu(ip->hw_id)], 1381 le16_to_cpu(ip->hw_id), 1382 ip->instance_number, 1383 ip->major, ip->minor, 1384 ip->revision); 1385 1386 if (le16_to_cpu(ip->hw_id) == VCN_HWID) { 1387 /* Bit [5:0]: original revision value 1388 * Bit [7:6]: en/decode capability: 1389 * 0b00 : VCN function normally 1390 * 0b10 : encode is disabled 1391 * 0b01 : decode is disabled 1392 */ 1393 if (adev->vcn.num_vcn_inst < 1394 AMDGPU_MAX_VCN_INSTANCES) { 1395 adev->vcn.inst[adev->vcn.num_vcn_inst].vcn_config = 1396 ip->revision & 0xc0; 1397 adev->vcn.num_vcn_inst++; 1398 adev->vcn.inst_mask |= 1399 (1U << ip->instance_number); 1400 adev->jpeg.inst_mask |= 1401 (1U << ip->instance_number); 1402 } else { 1403 dev_err(adev->dev, "Too many VCN instances: %d vs %d\n", 1404 adev->vcn.num_vcn_inst + 1, 1405 AMDGPU_MAX_VCN_INSTANCES); 1406 } 1407 ip->revision &= ~0xc0; 1408 } 1409 if (le16_to_cpu(ip->hw_id) == SDMA0_HWID || 1410 le16_to_cpu(ip->hw_id) == SDMA1_HWID || 1411 le16_to_cpu(ip->hw_id) == SDMA2_HWID || 1412 le16_to_cpu(ip->hw_id) == SDMA3_HWID) { 1413 if (adev->sdma.num_instances < 1414 AMDGPU_MAX_SDMA_INSTANCES) { 1415 adev->sdma.num_instances++; 1416 adev->sdma.sdma_mask |= 1417 (1U << ip->instance_number); 1418 } else { 1419 dev_err(adev->dev, "Too many SDMA instances: %d vs %d\n", 1420 adev->sdma.num_instances + 1, 1421 AMDGPU_MAX_SDMA_INSTANCES); 1422 } 1423 } 1424 1425 if (le16_to_cpu(ip->hw_id) == VPE_HWID) { 1426 if (adev->vpe.num_instances < AMDGPU_MAX_VPE_INSTANCES) 1427 adev->vpe.num_instances++; 1428 else 1429 dev_err(adev->dev, "Too many VPE instances: %d vs %d\n", 1430 adev->vpe.num_instances + 1, 1431 AMDGPU_MAX_VPE_INSTANCES); 1432 } 1433 1434 if (le16_to_cpu(ip->hw_id) == UMC_HWID) { 1435 adev->gmc.num_umc++; 1436 adev->umc.node_inst_num++; 1437 } 1438 1439 if (le16_to_cpu(ip->hw_id) == GC_HWID) 1440 adev->gfx.xcc_mask |= 1441 (1U << ip->instance_number); 1442 1443 if (!wafl_ver && le16_to_cpu(ip->hw_id) == WAFLC_HWID) 1444 wafl_ver = IP_VERSION_FULL(ip->major, ip->minor, 1445 ip->revision, 0, 0); 1446 1447 for (k = 0; k < num_base_address; k++) { 1448 /* 1449 * convert the endianness of base addresses in place, 1450 * so that we don't need to convert them when accessing adev->reg_offset. 1451 */ 1452 if (ihdr->base_addr_64_bit) 1453 /* Truncate the 64bit base address from ip discovery 1454 * and only store lower 32bit ip base in reg_offset[]. 1455 * Bits > 32 follows ASIC specific format, thus just 1456 * discard them and handle it within specific ASIC. 1457 * By this way reg_offset[] and related helpers can 1458 * stay unchanged. 1459 * The base address is in dwords, thus clear the 1460 * highest 2 bits to store. 1461 */ 1462 ip->base_address[k] = 1463 lower_32_bits(le64_to_cpu(ip->base_address_64[k])) & 0x3FFFFFFF; 1464 else 1465 ip->base_address[k] = le32_to_cpu(ip->base_address[k]); 1466 DRM_DEBUG("\t0x%08x\n", ip->base_address[k]); 1467 } 1468 1469 for (hw_ip = 0; hw_ip < MAX_HWIP; hw_ip++) { 1470 if (hw_id_map[hw_ip] == le16_to_cpu(ip->hw_id) && 1471 hw_id_map[hw_ip] != 0) { 1472 DRM_DEBUG("set register base offset for %s\n", 1473 hw_id_names[le16_to_cpu(ip->hw_id)]); 1474 adev->reg_offset[hw_ip][ip->instance_number] = 1475 ip->base_address; 1476 /* Instance support is somewhat inconsistent. 1477 * SDMA is a good example. Sienna cichlid has 4 total 1478 * SDMA instances, each enumerated separately (HWIDs 1479 * 42, 43, 68, 69). Arcturus has 8 total SDMA instances, 1480 * but they are enumerated as multiple instances of the 1481 * same HWIDs (4x HWID 42, 4x HWID 43). UMC is another 1482 * example. On most chips there are multiple instances 1483 * with the same HWID. 1484 */ 1485 1486 if (ihdr->version < 3) { 1487 subrev = 0; 1488 variant = 0; 1489 } else { 1490 subrev = ip->sub_revision; 1491 variant = ip->variant; 1492 } 1493 1494 adev->ip_versions[hw_ip] 1495 [ip->instance_number] = 1496 IP_VERSION_FULL(ip->major, 1497 ip->minor, 1498 ip->revision, 1499 variant, 1500 subrev); 1501 } 1502 } 1503 1504 next_ip: 1505 if (ihdr->base_addr_64_bit) 1506 ip_offset += struct_size(ip, base_address_64, ip->num_base_address); 1507 else 1508 ip_offset += struct_size(ip, base_address, ip->num_base_address); 1509 } 1510 } 1511 1512 if (wafl_ver && !adev->ip_versions[XGMI_HWIP][0]) 1513 adev->ip_versions[XGMI_HWIP][0] = wafl_ver; 1514 1515 return 0; 1516 } 1517 1518 static void amdgpu_discovery_harvest_ip(struct amdgpu_device *adev) 1519 { 1520 struct ip_discovery_header *ihdr; 1521 struct binary_header *bhdr; 1522 int vcn_harvest_count = 0; 1523 int umc_harvest_count = 0; 1524 uint16_t offset, ihdr_ver; 1525 1526 bhdr = (struct binary_header *)adev->mman.discovery_bin; 1527 offset = le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset); 1528 ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin + 1529 offset); 1530 ihdr_ver = le16_to_cpu(ihdr->version); 1531 /* 1532 * Harvest table does not fit Navi1x and legacy GPUs, 1533 * so read harvest bit per IP data structure to set 1534 * harvest configuration. 1535 */ 1536 if (amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(10, 2, 0) && 1537 ihdr_ver <= 2) { 1538 if ((adev->pdev->device == 0x731E && 1539 (adev->pdev->revision == 0xC6 || 1540 adev->pdev->revision == 0xC7)) || 1541 (adev->pdev->device == 0x7340 && 1542 adev->pdev->revision == 0xC9) || 1543 (adev->pdev->device == 0x7360 && 1544 adev->pdev->revision == 0xC7)) 1545 amdgpu_discovery_read_harvest_bit_per_ip(adev, 1546 &vcn_harvest_count); 1547 } else { 1548 amdgpu_discovery_read_from_harvest_table(adev, 1549 &vcn_harvest_count, 1550 &umc_harvest_count); 1551 } 1552 1553 amdgpu_discovery_harvest_config_quirk(adev); 1554 1555 if (vcn_harvest_count == adev->vcn.num_vcn_inst) { 1556 adev->harvest_ip_mask |= AMD_HARVEST_IP_VCN_MASK; 1557 adev->harvest_ip_mask |= AMD_HARVEST_IP_JPEG_MASK; 1558 } 1559 1560 if (umc_harvest_count < adev->gmc.num_umc) { 1561 adev->gmc.num_umc -= umc_harvest_count; 1562 } 1563 } 1564 1565 union gc_info { 1566 struct gc_info_v1_0 v1; 1567 struct gc_info_v1_1 v1_1; 1568 struct gc_info_v1_2 v1_2; 1569 struct gc_info_v1_3 v1_3; 1570 struct gc_info_v2_0 v2; 1571 struct gc_info_v2_1 v2_1; 1572 }; 1573 1574 static int amdgpu_discovery_get_gfx_info(struct amdgpu_device *adev) 1575 { 1576 struct binary_header *bhdr; 1577 union gc_info *gc_info; 1578 u16 offset; 1579 1580 if (!adev->mman.discovery_bin) { 1581 DRM_ERROR("ip discovery uninitialized\n"); 1582 return -EINVAL; 1583 } 1584 1585 bhdr = (struct binary_header *)adev->mman.discovery_bin; 1586 offset = le16_to_cpu(bhdr->table_list[GC].offset); 1587 1588 if (!offset) 1589 return 0; 1590 1591 gc_info = (union gc_info *)(adev->mman.discovery_bin + offset); 1592 1593 switch (le16_to_cpu(gc_info->v1.header.version_major)) { 1594 case 1: 1595 adev->gfx.config.max_shader_engines = le32_to_cpu(gc_info->v1.gc_num_se); 1596 adev->gfx.config.max_cu_per_sh = 2 * (le32_to_cpu(gc_info->v1.gc_num_wgp0_per_sa) + 1597 le32_to_cpu(gc_info->v1.gc_num_wgp1_per_sa)); 1598 adev->gfx.config.max_sh_per_se = le32_to_cpu(gc_info->v1.gc_num_sa_per_se); 1599 adev->gfx.config.max_backends_per_se = le32_to_cpu(gc_info->v1.gc_num_rb_per_se); 1600 adev->gfx.config.max_texture_channel_caches = le32_to_cpu(gc_info->v1.gc_num_gl2c); 1601 adev->gfx.config.max_gprs = le32_to_cpu(gc_info->v1.gc_num_gprs); 1602 adev->gfx.config.max_gs_threads = le32_to_cpu(gc_info->v1.gc_num_max_gs_thds); 1603 adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gc_info->v1.gc_gs_table_depth); 1604 adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gc_info->v1.gc_gsprim_buff_depth); 1605 adev->gfx.config.double_offchip_lds_buf = le32_to_cpu(gc_info->v1.gc_double_offchip_lds_buffer); 1606 adev->gfx.cu_info.wave_front_size = le32_to_cpu(gc_info->v1.gc_wave_size); 1607 adev->gfx.cu_info.max_waves_per_simd = le32_to_cpu(gc_info->v1.gc_max_waves_per_simd); 1608 adev->gfx.cu_info.max_scratch_slots_per_cu = le32_to_cpu(gc_info->v1.gc_max_scratch_slots_per_cu); 1609 adev->gfx.cu_info.lds_size = le32_to_cpu(gc_info->v1.gc_lds_size); 1610 adev->gfx.config.num_sc_per_sh = le32_to_cpu(gc_info->v1.gc_num_sc_per_se) / 1611 le32_to_cpu(gc_info->v1.gc_num_sa_per_se); 1612 adev->gfx.config.num_packer_per_sc = le32_to_cpu(gc_info->v1.gc_num_packer_per_sc); 1613 if (le16_to_cpu(gc_info->v1.header.version_minor) >= 1) { 1614 adev->gfx.config.gc_num_tcp_per_sa = le32_to_cpu(gc_info->v1_1.gc_num_tcp_per_sa); 1615 adev->gfx.config.gc_num_sdp_interface = le32_to_cpu(gc_info->v1_1.gc_num_sdp_interface); 1616 adev->gfx.config.gc_num_tcps = le32_to_cpu(gc_info->v1_1.gc_num_tcps); 1617 } 1618 if (le16_to_cpu(gc_info->v1.header.version_minor) >= 2) { 1619 adev->gfx.config.gc_num_tcp_per_wpg = le32_to_cpu(gc_info->v1_2.gc_num_tcp_per_wpg); 1620 adev->gfx.config.gc_tcp_l1_size = le32_to_cpu(gc_info->v1_2.gc_tcp_l1_size); 1621 adev->gfx.config.gc_num_sqc_per_wgp = le32_to_cpu(gc_info->v1_2.gc_num_sqc_per_wgp); 1622 adev->gfx.config.gc_l1_instruction_cache_size_per_sqc = le32_to_cpu(gc_info->v1_2.gc_l1_instruction_cache_size_per_sqc); 1623 adev->gfx.config.gc_l1_data_cache_size_per_sqc = le32_to_cpu(gc_info->v1_2.gc_l1_data_cache_size_per_sqc); 1624 adev->gfx.config.gc_gl1c_per_sa = le32_to_cpu(gc_info->v1_2.gc_gl1c_per_sa); 1625 adev->gfx.config.gc_gl1c_size_per_instance = le32_to_cpu(gc_info->v1_2.gc_gl1c_size_per_instance); 1626 adev->gfx.config.gc_gl2c_per_gpu = le32_to_cpu(gc_info->v1_2.gc_gl2c_per_gpu); 1627 } 1628 if (le16_to_cpu(gc_info->v1.header.version_minor) >= 3) { 1629 adev->gfx.config.gc_tcp_size_per_cu = le32_to_cpu(gc_info->v1_3.gc_tcp_size_per_cu); 1630 adev->gfx.config.gc_tcp_cache_line_size = le32_to_cpu(gc_info->v1_3.gc_tcp_cache_line_size); 1631 adev->gfx.config.gc_instruction_cache_size_per_sqc = le32_to_cpu(gc_info->v1_3.gc_instruction_cache_size_per_sqc); 1632 adev->gfx.config.gc_instruction_cache_line_size = le32_to_cpu(gc_info->v1_3.gc_instruction_cache_line_size); 1633 adev->gfx.config.gc_scalar_data_cache_size_per_sqc = le32_to_cpu(gc_info->v1_3.gc_scalar_data_cache_size_per_sqc); 1634 adev->gfx.config.gc_scalar_data_cache_line_size = le32_to_cpu(gc_info->v1_3.gc_scalar_data_cache_line_size); 1635 adev->gfx.config.gc_tcc_size = le32_to_cpu(gc_info->v1_3.gc_tcc_size); 1636 adev->gfx.config.gc_tcc_cache_line_size = le32_to_cpu(gc_info->v1_3.gc_tcc_cache_line_size); 1637 } 1638 break; 1639 case 2: 1640 adev->gfx.config.max_shader_engines = le32_to_cpu(gc_info->v2.gc_num_se); 1641 adev->gfx.config.max_cu_per_sh = le32_to_cpu(gc_info->v2.gc_num_cu_per_sh); 1642 adev->gfx.config.max_sh_per_se = le32_to_cpu(gc_info->v2.gc_num_sh_per_se); 1643 adev->gfx.config.max_backends_per_se = le32_to_cpu(gc_info->v2.gc_num_rb_per_se); 1644 adev->gfx.config.max_texture_channel_caches = le32_to_cpu(gc_info->v2.gc_num_tccs); 1645 adev->gfx.config.max_gprs = le32_to_cpu(gc_info->v2.gc_num_gprs); 1646 adev->gfx.config.max_gs_threads = le32_to_cpu(gc_info->v2.gc_num_max_gs_thds); 1647 adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gc_info->v2.gc_gs_table_depth); 1648 adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gc_info->v2.gc_gsprim_buff_depth); 1649 adev->gfx.config.double_offchip_lds_buf = le32_to_cpu(gc_info->v2.gc_double_offchip_lds_buffer); 1650 adev->gfx.cu_info.wave_front_size = le32_to_cpu(gc_info->v2.gc_wave_size); 1651 adev->gfx.cu_info.max_waves_per_simd = le32_to_cpu(gc_info->v2.gc_max_waves_per_simd); 1652 adev->gfx.cu_info.max_scratch_slots_per_cu = le32_to_cpu(gc_info->v2.gc_max_scratch_slots_per_cu); 1653 adev->gfx.cu_info.lds_size = le32_to_cpu(gc_info->v2.gc_lds_size); 1654 adev->gfx.config.num_sc_per_sh = le32_to_cpu(gc_info->v2.gc_num_sc_per_se) / 1655 le32_to_cpu(gc_info->v2.gc_num_sh_per_se); 1656 adev->gfx.config.num_packer_per_sc = le32_to_cpu(gc_info->v2.gc_num_packer_per_sc); 1657 if (le16_to_cpu(gc_info->v2.header.version_minor) == 1) { 1658 adev->gfx.config.gc_num_tcp_per_sa = le32_to_cpu(gc_info->v2_1.gc_num_tcp_per_sh); 1659 adev->gfx.config.gc_tcp_size_per_cu = le32_to_cpu(gc_info->v2_1.gc_tcp_size_per_cu); 1660 adev->gfx.config.gc_num_sdp_interface = le32_to_cpu(gc_info->v2_1.gc_num_sdp_interface); /* per XCD */ 1661 adev->gfx.config.gc_num_cu_per_sqc = le32_to_cpu(gc_info->v2_1.gc_num_cu_per_sqc); 1662 adev->gfx.config.gc_l1_instruction_cache_size_per_sqc = le32_to_cpu(gc_info->v2_1.gc_instruction_cache_size_per_sqc); 1663 adev->gfx.config.gc_l1_data_cache_size_per_sqc = le32_to_cpu(gc_info->v2_1.gc_scalar_data_cache_size_per_sqc); 1664 adev->gfx.config.gc_tcc_size = le32_to_cpu(gc_info->v2_1.gc_tcc_size); /* per XCD */ 1665 } 1666 break; 1667 default: 1668 dev_err(adev->dev, 1669 "Unhandled GC info table %d.%d\n", 1670 le16_to_cpu(gc_info->v1.header.version_major), 1671 le16_to_cpu(gc_info->v1.header.version_minor)); 1672 return -EINVAL; 1673 } 1674 return 0; 1675 } 1676 1677 union mall_info { 1678 struct mall_info_v1_0 v1; 1679 struct mall_info_v2_0 v2; 1680 }; 1681 1682 static int amdgpu_discovery_get_mall_info(struct amdgpu_device *adev) 1683 { 1684 struct binary_header *bhdr; 1685 union mall_info *mall_info; 1686 u32 u, mall_size_per_umc, m_s_present, half_use; 1687 u64 mall_size; 1688 u16 offset; 1689 1690 if (!adev->mman.discovery_bin) { 1691 DRM_ERROR("ip discovery uninitialized\n"); 1692 return -EINVAL; 1693 } 1694 1695 bhdr = (struct binary_header *)adev->mman.discovery_bin; 1696 offset = le16_to_cpu(bhdr->table_list[MALL_INFO].offset); 1697 1698 if (!offset) 1699 return 0; 1700 1701 mall_info = (union mall_info *)(adev->mman.discovery_bin + offset); 1702 1703 switch (le16_to_cpu(mall_info->v1.header.version_major)) { 1704 case 1: 1705 mall_size = 0; 1706 mall_size_per_umc = le32_to_cpu(mall_info->v1.mall_size_per_m); 1707 m_s_present = le32_to_cpu(mall_info->v1.m_s_present); 1708 half_use = le32_to_cpu(mall_info->v1.m_half_use); 1709 for (u = 0; u < adev->gmc.num_umc; u++) { 1710 if (m_s_present & (1 << u)) 1711 mall_size += mall_size_per_umc * 2; 1712 else if (half_use & (1 << u)) 1713 mall_size += mall_size_per_umc / 2; 1714 else 1715 mall_size += mall_size_per_umc; 1716 } 1717 adev->gmc.mall_size = mall_size; 1718 adev->gmc.m_half_use = half_use; 1719 break; 1720 case 2: 1721 mall_size_per_umc = le32_to_cpu(mall_info->v2.mall_size_per_umc); 1722 adev->gmc.mall_size = (uint64_t)mall_size_per_umc * adev->gmc.num_umc; 1723 break; 1724 default: 1725 dev_err(adev->dev, 1726 "Unhandled MALL info table %d.%d\n", 1727 le16_to_cpu(mall_info->v1.header.version_major), 1728 le16_to_cpu(mall_info->v1.header.version_minor)); 1729 return -EINVAL; 1730 } 1731 return 0; 1732 } 1733 1734 union vcn_info { 1735 struct vcn_info_v1_0 v1; 1736 }; 1737 1738 static int amdgpu_discovery_get_vcn_info(struct amdgpu_device *adev) 1739 { 1740 struct binary_header *bhdr; 1741 union vcn_info *vcn_info; 1742 u16 offset; 1743 int v; 1744 1745 if (!adev->mman.discovery_bin) { 1746 DRM_ERROR("ip discovery uninitialized\n"); 1747 return -EINVAL; 1748 } 1749 1750 /* num_vcn_inst is currently limited to AMDGPU_MAX_VCN_INSTANCES 1751 * which is smaller than VCN_INFO_TABLE_MAX_NUM_INSTANCES 1752 * but that may change in the future with new GPUs so keep this 1753 * check for defensive purposes. 1754 */ 1755 if (adev->vcn.num_vcn_inst > VCN_INFO_TABLE_MAX_NUM_INSTANCES) { 1756 dev_err(adev->dev, "invalid vcn instances\n"); 1757 return -EINVAL; 1758 } 1759 1760 bhdr = (struct binary_header *)adev->mman.discovery_bin; 1761 offset = le16_to_cpu(bhdr->table_list[VCN_INFO].offset); 1762 1763 if (!offset) 1764 return 0; 1765 1766 vcn_info = (union vcn_info *)(adev->mman.discovery_bin + offset); 1767 1768 switch (le16_to_cpu(vcn_info->v1.header.version_major)) { 1769 case 1: 1770 /* num_vcn_inst is currently limited to AMDGPU_MAX_VCN_INSTANCES 1771 * so this won't overflow. 1772 */ 1773 for (v = 0; v < adev->vcn.num_vcn_inst; v++) { 1774 adev->vcn.inst[v].vcn_codec_disable_mask = 1775 le32_to_cpu(vcn_info->v1.instance_info[v].fuse_data.all_bits); 1776 } 1777 break; 1778 default: 1779 dev_err(adev->dev, 1780 "Unhandled VCN info table %d.%d\n", 1781 le16_to_cpu(vcn_info->v1.header.version_major), 1782 le16_to_cpu(vcn_info->v1.header.version_minor)); 1783 return -EINVAL; 1784 } 1785 return 0; 1786 } 1787 1788 union nps_info { 1789 struct nps_info_v1_0 v1; 1790 }; 1791 1792 static int amdgpu_discovery_refresh_nps_info(struct amdgpu_device *adev, 1793 union nps_info *nps_data) 1794 { 1795 uint64_t vram_size, pos, offset; 1796 struct nps_info_header *nhdr; 1797 struct binary_header bhdr; 1798 uint16_t checksum; 1799 1800 vram_size = (uint64_t)RREG32(mmRCC_CONFIG_MEMSIZE) << 20; 1801 pos = vram_size - DISCOVERY_TMR_OFFSET; 1802 amdgpu_device_vram_access(adev, pos, &bhdr, sizeof(bhdr), false); 1803 1804 offset = le16_to_cpu(bhdr.table_list[NPS_INFO].offset); 1805 checksum = le16_to_cpu(bhdr.table_list[NPS_INFO].checksum); 1806 1807 amdgpu_device_vram_access(adev, (pos + offset), nps_data, 1808 sizeof(*nps_data), false); 1809 1810 nhdr = (struct nps_info_header *)(nps_data); 1811 if (!amdgpu_discovery_verify_checksum((uint8_t *)nps_data, 1812 le32_to_cpu(nhdr->size_bytes), 1813 checksum)) { 1814 dev_err(adev->dev, "nps data refresh, checksum mismatch\n"); 1815 return -EINVAL; 1816 } 1817 1818 return 0; 1819 } 1820 1821 int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev, 1822 uint32_t *nps_type, 1823 struct amdgpu_gmc_memrange **ranges, 1824 int *range_cnt, bool refresh) 1825 { 1826 struct amdgpu_gmc_memrange *mem_ranges; 1827 struct binary_header *bhdr; 1828 union nps_info *nps_info; 1829 union nps_info nps_data; 1830 u16 offset; 1831 int i, r; 1832 1833 if (!nps_type || !range_cnt || !ranges) 1834 return -EINVAL; 1835 1836 if (refresh) { 1837 r = amdgpu_discovery_refresh_nps_info(adev, &nps_data); 1838 if (r) 1839 return r; 1840 nps_info = &nps_data; 1841 } else { 1842 if (!adev->mman.discovery_bin) { 1843 dev_err(adev->dev, 1844 "fetch mem range failed, ip discovery uninitialized\n"); 1845 return -EINVAL; 1846 } 1847 1848 bhdr = (struct binary_header *)adev->mman.discovery_bin; 1849 offset = le16_to_cpu(bhdr->table_list[NPS_INFO].offset); 1850 1851 if (!offset) 1852 return -ENOENT; 1853 1854 /* If verification fails, return as if NPS table doesn't exist */ 1855 if (amdgpu_discovery_verify_npsinfo(adev, bhdr)) 1856 return -ENOENT; 1857 1858 nps_info = 1859 (union nps_info *)(adev->mman.discovery_bin + offset); 1860 } 1861 1862 switch (le16_to_cpu(nps_info->v1.header.version_major)) { 1863 case 1: 1864 mem_ranges = kvcalloc(nps_info->v1.count, 1865 sizeof(*mem_ranges), 1866 GFP_KERNEL); 1867 if (!mem_ranges) 1868 return -ENOMEM; 1869 *nps_type = nps_info->v1.nps_type; 1870 *range_cnt = nps_info->v1.count; 1871 for (i = 0; i < *range_cnt; i++) { 1872 mem_ranges[i].base_address = 1873 nps_info->v1.instance_info[i].base_address; 1874 mem_ranges[i].limit_address = 1875 nps_info->v1.instance_info[i].limit_address; 1876 mem_ranges[i].nid_mask = -1; 1877 mem_ranges[i].flags = 0; 1878 } 1879 *ranges = mem_ranges; 1880 break; 1881 default: 1882 dev_err(adev->dev, "Unhandled NPS info table %d.%d\n", 1883 le16_to_cpu(nps_info->v1.header.version_major), 1884 le16_to_cpu(nps_info->v1.header.version_minor)); 1885 return -EINVAL; 1886 } 1887 1888 return 0; 1889 } 1890 1891 static int amdgpu_discovery_set_common_ip_blocks(struct amdgpu_device *adev) 1892 { 1893 /* what IP to use for this? */ 1894 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 1895 case IP_VERSION(9, 0, 1): 1896 case IP_VERSION(9, 1, 0): 1897 case IP_VERSION(9, 2, 1): 1898 case IP_VERSION(9, 2, 2): 1899 case IP_VERSION(9, 3, 0): 1900 case IP_VERSION(9, 4, 0): 1901 case IP_VERSION(9, 4, 1): 1902 case IP_VERSION(9, 4, 2): 1903 case IP_VERSION(9, 4, 3): 1904 case IP_VERSION(9, 4, 4): 1905 case IP_VERSION(9, 5, 0): 1906 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block); 1907 break; 1908 case IP_VERSION(10, 1, 10): 1909 case IP_VERSION(10, 1, 1): 1910 case IP_VERSION(10, 1, 2): 1911 case IP_VERSION(10, 1, 3): 1912 case IP_VERSION(10, 1, 4): 1913 case IP_VERSION(10, 3, 0): 1914 case IP_VERSION(10, 3, 1): 1915 case IP_VERSION(10, 3, 2): 1916 case IP_VERSION(10, 3, 3): 1917 case IP_VERSION(10, 3, 4): 1918 case IP_VERSION(10, 3, 5): 1919 case IP_VERSION(10, 3, 6): 1920 case IP_VERSION(10, 3, 7): 1921 amdgpu_device_ip_block_add(adev, &nv_common_ip_block); 1922 break; 1923 case IP_VERSION(11, 0, 0): 1924 case IP_VERSION(11, 0, 1): 1925 case IP_VERSION(11, 0, 2): 1926 case IP_VERSION(11, 0, 3): 1927 case IP_VERSION(11, 0, 4): 1928 case IP_VERSION(11, 5, 0): 1929 case IP_VERSION(11, 5, 1): 1930 case IP_VERSION(11, 5, 2): 1931 case IP_VERSION(11, 5, 3): 1932 amdgpu_device_ip_block_add(adev, &soc21_common_ip_block); 1933 break; 1934 case IP_VERSION(12, 0, 0): 1935 case IP_VERSION(12, 0, 1): 1936 amdgpu_device_ip_block_add(adev, &soc24_common_ip_block); 1937 break; 1938 default: 1939 dev_err(adev->dev, 1940 "Failed to add common ip block(GC_HWIP:0x%x)\n", 1941 amdgpu_ip_version(adev, GC_HWIP, 0)); 1942 return -EINVAL; 1943 } 1944 return 0; 1945 } 1946 1947 static int amdgpu_discovery_set_gmc_ip_blocks(struct amdgpu_device *adev) 1948 { 1949 /* use GC or MMHUB IP version */ 1950 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 1951 case IP_VERSION(9, 0, 1): 1952 case IP_VERSION(9, 1, 0): 1953 case IP_VERSION(9, 2, 1): 1954 case IP_VERSION(9, 2, 2): 1955 case IP_VERSION(9, 3, 0): 1956 case IP_VERSION(9, 4, 0): 1957 case IP_VERSION(9, 4, 1): 1958 case IP_VERSION(9, 4, 2): 1959 case IP_VERSION(9, 4, 3): 1960 case IP_VERSION(9, 4, 4): 1961 case IP_VERSION(9, 5, 0): 1962 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block); 1963 break; 1964 case IP_VERSION(10, 1, 10): 1965 case IP_VERSION(10, 1, 1): 1966 case IP_VERSION(10, 1, 2): 1967 case IP_VERSION(10, 1, 3): 1968 case IP_VERSION(10, 1, 4): 1969 case IP_VERSION(10, 3, 0): 1970 case IP_VERSION(10, 3, 1): 1971 case IP_VERSION(10, 3, 2): 1972 case IP_VERSION(10, 3, 3): 1973 case IP_VERSION(10, 3, 4): 1974 case IP_VERSION(10, 3, 5): 1975 case IP_VERSION(10, 3, 6): 1976 case IP_VERSION(10, 3, 7): 1977 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block); 1978 break; 1979 case IP_VERSION(11, 0, 0): 1980 case IP_VERSION(11, 0, 1): 1981 case IP_VERSION(11, 0, 2): 1982 case IP_VERSION(11, 0, 3): 1983 case IP_VERSION(11, 0, 4): 1984 case IP_VERSION(11, 5, 0): 1985 case IP_VERSION(11, 5, 1): 1986 case IP_VERSION(11, 5, 2): 1987 case IP_VERSION(11, 5, 3): 1988 amdgpu_device_ip_block_add(adev, &gmc_v11_0_ip_block); 1989 break; 1990 case IP_VERSION(12, 0, 0): 1991 case IP_VERSION(12, 0, 1): 1992 amdgpu_device_ip_block_add(adev, &gmc_v12_0_ip_block); 1993 break; 1994 default: 1995 dev_err(adev->dev, "Failed to add gmc ip block(GC_HWIP:0x%x)\n", 1996 amdgpu_ip_version(adev, GC_HWIP, 0)); 1997 return -EINVAL; 1998 } 1999 return 0; 2000 } 2001 2002 static int amdgpu_discovery_set_ih_ip_blocks(struct amdgpu_device *adev) 2003 { 2004 switch (amdgpu_ip_version(adev, OSSSYS_HWIP, 0)) { 2005 case IP_VERSION(4, 0, 0): 2006 case IP_VERSION(4, 0, 1): 2007 case IP_VERSION(4, 1, 0): 2008 case IP_VERSION(4, 1, 1): 2009 case IP_VERSION(4, 3, 0): 2010 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block); 2011 break; 2012 case IP_VERSION(4, 2, 0): 2013 case IP_VERSION(4, 2, 1): 2014 case IP_VERSION(4, 4, 0): 2015 case IP_VERSION(4, 4, 2): 2016 case IP_VERSION(4, 4, 5): 2017 amdgpu_device_ip_block_add(adev, &vega20_ih_ip_block); 2018 break; 2019 case IP_VERSION(5, 0, 0): 2020 case IP_VERSION(5, 0, 1): 2021 case IP_VERSION(5, 0, 2): 2022 case IP_VERSION(5, 0, 3): 2023 case IP_VERSION(5, 2, 0): 2024 case IP_VERSION(5, 2, 1): 2025 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block); 2026 break; 2027 case IP_VERSION(6, 0, 0): 2028 case IP_VERSION(6, 0, 1): 2029 case IP_VERSION(6, 0, 2): 2030 amdgpu_device_ip_block_add(adev, &ih_v6_0_ip_block); 2031 break; 2032 case IP_VERSION(6, 1, 0): 2033 amdgpu_device_ip_block_add(adev, &ih_v6_1_ip_block); 2034 break; 2035 case IP_VERSION(7, 0, 0): 2036 amdgpu_device_ip_block_add(adev, &ih_v7_0_ip_block); 2037 break; 2038 default: 2039 dev_err(adev->dev, 2040 "Failed to add ih ip block(OSSSYS_HWIP:0x%x)\n", 2041 amdgpu_ip_version(adev, OSSSYS_HWIP, 0)); 2042 return -EINVAL; 2043 } 2044 return 0; 2045 } 2046 2047 static int amdgpu_discovery_set_psp_ip_blocks(struct amdgpu_device *adev) 2048 { 2049 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) { 2050 case IP_VERSION(9, 0, 0): 2051 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block); 2052 break; 2053 case IP_VERSION(10, 0, 0): 2054 case IP_VERSION(10, 0, 1): 2055 amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block); 2056 break; 2057 case IP_VERSION(11, 0, 0): 2058 case IP_VERSION(11, 0, 2): 2059 case IP_VERSION(11, 0, 4): 2060 case IP_VERSION(11, 0, 5): 2061 case IP_VERSION(11, 0, 9): 2062 case IP_VERSION(11, 0, 7): 2063 case IP_VERSION(11, 0, 11): 2064 case IP_VERSION(11, 0, 12): 2065 case IP_VERSION(11, 0, 13): 2066 case IP_VERSION(11, 5, 0): 2067 case IP_VERSION(11, 5, 2): 2068 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block); 2069 break; 2070 case IP_VERSION(11, 0, 8): 2071 amdgpu_device_ip_block_add(adev, &psp_v11_0_8_ip_block); 2072 break; 2073 case IP_VERSION(11, 0, 3): 2074 case IP_VERSION(12, 0, 1): 2075 amdgpu_device_ip_block_add(adev, &psp_v12_0_ip_block); 2076 break; 2077 case IP_VERSION(13, 0, 0): 2078 case IP_VERSION(13, 0, 1): 2079 case IP_VERSION(13, 0, 2): 2080 case IP_VERSION(13, 0, 3): 2081 case IP_VERSION(13, 0, 5): 2082 case IP_VERSION(13, 0, 6): 2083 case IP_VERSION(13, 0, 7): 2084 case IP_VERSION(13, 0, 8): 2085 case IP_VERSION(13, 0, 10): 2086 case IP_VERSION(13, 0, 11): 2087 case IP_VERSION(13, 0, 12): 2088 case IP_VERSION(13, 0, 14): 2089 case IP_VERSION(14, 0, 0): 2090 case IP_VERSION(14, 0, 1): 2091 case IP_VERSION(14, 0, 4): 2092 amdgpu_device_ip_block_add(adev, &psp_v13_0_ip_block); 2093 break; 2094 case IP_VERSION(13, 0, 4): 2095 amdgpu_device_ip_block_add(adev, &psp_v13_0_4_ip_block); 2096 break; 2097 case IP_VERSION(14, 0, 2): 2098 case IP_VERSION(14, 0, 3): 2099 case IP_VERSION(14, 0, 5): 2100 amdgpu_device_ip_block_add(adev, &psp_v14_0_ip_block); 2101 break; 2102 default: 2103 dev_err(adev->dev, 2104 "Failed to add psp ip block(MP0_HWIP:0x%x)\n", 2105 amdgpu_ip_version(adev, MP0_HWIP, 0)); 2106 return -EINVAL; 2107 } 2108 return 0; 2109 } 2110 2111 static int amdgpu_discovery_set_smu_ip_blocks(struct amdgpu_device *adev) 2112 { 2113 switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) { 2114 case IP_VERSION(9, 0, 0): 2115 case IP_VERSION(10, 0, 0): 2116 case IP_VERSION(10, 0, 1): 2117 case IP_VERSION(11, 0, 2): 2118 if (adev->asic_type == CHIP_ARCTURUS) 2119 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); 2120 else 2121 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block); 2122 break; 2123 case IP_VERSION(11, 0, 0): 2124 case IP_VERSION(11, 0, 5): 2125 case IP_VERSION(11, 0, 9): 2126 case IP_VERSION(11, 0, 7): 2127 case IP_VERSION(11, 0, 11): 2128 case IP_VERSION(11, 0, 12): 2129 case IP_VERSION(11, 0, 13): 2130 case IP_VERSION(11, 5, 0): 2131 case IP_VERSION(11, 5, 2): 2132 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); 2133 break; 2134 case IP_VERSION(11, 0, 8): 2135 if (adev->apu_flags & AMD_APU_IS_CYAN_SKILLFISH2) 2136 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); 2137 break; 2138 case IP_VERSION(12, 0, 0): 2139 case IP_VERSION(12, 0, 1): 2140 amdgpu_device_ip_block_add(adev, &smu_v12_0_ip_block); 2141 break; 2142 case IP_VERSION(13, 0, 0): 2143 case IP_VERSION(13, 0, 1): 2144 case IP_VERSION(13, 0, 2): 2145 case IP_VERSION(13, 0, 3): 2146 case IP_VERSION(13, 0, 4): 2147 case IP_VERSION(13, 0, 5): 2148 case IP_VERSION(13, 0, 6): 2149 case IP_VERSION(13, 0, 7): 2150 case IP_VERSION(13, 0, 8): 2151 case IP_VERSION(13, 0, 10): 2152 case IP_VERSION(13, 0, 11): 2153 case IP_VERSION(13, 0, 14): 2154 case IP_VERSION(13, 0, 12): 2155 amdgpu_device_ip_block_add(adev, &smu_v13_0_ip_block); 2156 break; 2157 case IP_VERSION(14, 0, 0): 2158 case IP_VERSION(14, 0, 1): 2159 case IP_VERSION(14, 0, 2): 2160 case IP_VERSION(14, 0, 3): 2161 case IP_VERSION(14, 0, 4): 2162 case IP_VERSION(14, 0, 5): 2163 amdgpu_device_ip_block_add(adev, &smu_v14_0_ip_block); 2164 break; 2165 default: 2166 dev_err(adev->dev, 2167 "Failed to add smu ip block(MP1_HWIP:0x%x)\n", 2168 amdgpu_ip_version(adev, MP1_HWIP, 0)); 2169 return -EINVAL; 2170 } 2171 return 0; 2172 } 2173 2174 #if defined(CONFIG_DRM_AMD_DC) 2175 static void amdgpu_discovery_set_sriov_display(struct amdgpu_device *adev) 2176 { 2177 amdgpu_device_set_sriov_virtual_display(adev); 2178 amdgpu_device_ip_block_add(adev, &amdgpu_vkms_ip_block); 2179 } 2180 #endif 2181 2182 static int amdgpu_discovery_set_display_ip_blocks(struct amdgpu_device *adev) 2183 { 2184 if (adev->enable_virtual_display) { 2185 amdgpu_device_ip_block_add(adev, &amdgpu_vkms_ip_block); 2186 return 0; 2187 } 2188 2189 if (!amdgpu_device_has_dc_support(adev)) 2190 return 0; 2191 2192 #if defined(CONFIG_DRM_AMD_DC) 2193 if (amdgpu_ip_version(adev, DCE_HWIP, 0)) { 2194 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) { 2195 case IP_VERSION(1, 0, 0): 2196 case IP_VERSION(1, 0, 1): 2197 case IP_VERSION(2, 0, 2): 2198 case IP_VERSION(2, 0, 0): 2199 case IP_VERSION(2, 0, 3): 2200 case IP_VERSION(2, 1, 0): 2201 case IP_VERSION(3, 0, 0): 2202 case IP_VERSION(3, 0, 2): 2203 case IP_VERSION(3, 0, 3): 2204 case IP_VERSION(3, 0, 1): 2205 case IP_VERSION(3, 1, 2): 2206 case IP_VERSION(3, 1, 3): 2207 case IP_VERSION(3, 1, 4): 2208 case IP_VERSION(3, 1, 5): 2209 case IP_VERSION(3, 1, 6): 2210 case IP_VERSION(3, 2, 0): 2211 case IP_VERSION(3, 2, 1): 2212 case IP_VERSION(3, 5, 0): 2213 case IP_VERSION(3, 5, 1): 2214 case IP_VERSION(3, 6, 0): 2215 case IP_VERSION(4, 1, 0): 2216 /* TODO: Fix IP version. DC code expects version 4.0.1 */ 2217 if (adev->ip_versions[DCE_HWIP][0] == IP_VERSION(4, 1, 0)) 2218 adev->ip_versions[DCE_HWIP][0] = IP_VERSION(4, 0, 1); 2219 2220 if (amdgpu_sriov_vf(adev)) 2221 amdgpu_discovery_set_sriov_display(adev); 2222 else 2223 amdgpu_device_ip_block_add(adev, &dm_ip_block); 2224 break; 2225 default: 2226 dev_err(adev->dev, 2227 "Failed to add dm ip block(DCE_HWIP:0x%x)\n", 2228 amdgpu_ip_version(adev, DCE_HWIP, 0)); 2229 return -EINVAL; 2230 } 2231 } else if (amdgpu_ip_version(adev, DCI_HWIP, 0)) { 2232 switch (amdgpu_ip_version(adev, DCI_HWIP, 0)) { 2233 case IP_VERSION(12, 0, 0): 2234 case IP_VERSION(12, 0, 1): 2235 case IP_VERSION(12, 1, 0): 2236 if (amdgpu_sriov_vf(adev)) 2237 amdgpu_discovery_set_sriov_display(adev); 2238 else 2239 amdgpu_device_ip_block_add(adev, &dm_ip_block); 2240 break; 2241 default: 2242 dev_err(adev->dev, 2243 "Failed to add dm ip block(DCI_HWIP:0x%x)\n", 2244 amdgpu_ip_version(adev, DCI_HWIP, 0)); 2245 return -EINVAL; 2246 } 2247 } 2248 #endif 2249 return 0; 2250 } 2251 2252 static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev) 2253 { 2254 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 2255 case IP_VERSION(9, 0, 1): 2256 case IP_VERSION(9, 1, 0): 2257 case IP_VERSION(9, 2, 1): 2258 case IP_VERSION(9, 2, 2): 2259 case IP_VERSION(9, 3, 0): 2260 case IP_VERSION(9, 4, 0): 2261 case IP_VERSION(9, 4, 1): 2262 case IP_VERSION(9, 4, 2): 2263 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block); 2264 break; 2265 case IP_VERSION(9, 4, 3): 2266 case IP_VERSION(9, 4, 4): 2267 case IP_VERSION(9, 5, 0): 2268 amdgpu_device_ip_block_add(adev, &gfx_v9_4_3_ip_block); 2269 break; 2270 case IP_VERSION(10, 1, 10): 2271 case IP_VERSION(10, 1, 2): 2272 case IP_VERSION(10, 1, 1): 2273 case IP_VERSION(10, 1, 3): 2274 case IP_VERSION(10, 1, 4): 2275 case IP_VERSION(10, 3, 0): 2276 case IP_VERSION(10, 3, 2): 2277 case IP_VERSION(10, 3, 1): 2278 case IP_VERSION(10, 3, 4): 2279 case IP_VERSION(10, 3, 5): 2280 case IP_VERSION(10, 3, 6): 2281 case IP_VERSION(10, 3, 3): 2282 case IP_VERSION(10, 3, 7): 2283 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block); 2284 break; 2285 case IP_VERSION(11, 0, 0): 2286 case IP_VERSION(11, 0, 1): 2287 case IP_VERSION(11, 0, 2): 2288 case IP_VERSION(11, 0, 3): 2289 case IP_VERSION(11, 0, 4): 2290 case IP_VERSION(11, 5, 0): 2291 case IP_VERSION(11, 5, 1): 2292 case IP_VERSION(11, 5, 2): 2293 case IP_VERSION(11, 5, 3): 2294 amdgpu_device_ip_block_add(adev, &gfx_v11_0_ip_block); 2295 break; 2296 case IP_VERSION(12, 0, 0): 2297 case IP_VERSION(12, 0, 1): 2298 amdgpu_device_ip_block_add(adev, &gfx_v12_0_ip_block); 2299 break; 2300 default: 2301 dev_err(adev->dev, "Failed to add gfx ip block(GC_HWIP:0x%x)\n", 2302 amdgpu_ip_version(adev, GC_HWIP, 0)); 2303 return -EINVAL; 2304 } 2305 return 0; 2306 } 2307 2308 static int amdgpu_discovery_set_sdma_ip_blocks(struct amdgpu_device *adev) 2309 { 2310 switch (amdgpu_ip_version(adev, SDMA0_HWIP, 0)) { 2311 case IP_VERSION(4, 0, 0): 2312 case IP_VERSION(4, 0, 1): 2313 case IP_VERSION(4, 1, 0): 2314 case IP_VERSION(4, 1, 1): 2315 case IP_VERSION(4, 1, 2): 2316 case IP_VERSION(4, 2, 0): 2317 case IP_VERSION(4, 2, 2): 2318 case IP_VERSION(4, 4, 0): 2319 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block); 2320 break; 2321 case IP_VERSION(4, 4, 2): 2322 case IP_VERSION(4, 4, 5): 2323 case IP_VERSION(4, 4, 4): 2324 amdgpu_device_ip_block_add(adev, &sdma_v4_4_2_ip_block); 2325 break; 2326 case IP_VERSION(5, 0, 0): 2327 case IP_VERSION(5, 0, 1): 2328 case IP_VERSION(5, 0, 2): 2329 case IP_VERSION(5, 0, 5): 2330 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block); 2331 break; 2332 case IP_VERSION(5, 2, 0): 2333 case IP_VERSION(5, 2, 2): 2334 case IP_VERSION(5, 2, 4): 2335 case IP_VERSION(5, 2, 5): 2336 case IP_VERSION(5, 2, 6): 2337 case IP_VERSION(5, 2, 3): 2338 case IP_VERSION(5, 2, 1): 2339 case IP_VERSION(5, 2, 7): 2340 amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block); 2341 break; 2342 case IP_VERSION(6, 0, 0): 2343 case IP_VERSION(6, 0, 1): 2344 case IP_VERSION(6, 0, 2): 2345 case IP_VERSION(6, 0, 3): 2346 case IP_VERSION(6, 1, 0): 2347 case IP_VERSION(6, 1, 1): 2348 case IP_VERSION(6, 1, 2): 2349 case IP_VERSION(6, 1, 3): 2350 amdgpu_device_ip_block_add(adev, &sdma_v6_0_ip_block); 2351 break; 2352 case IP_VERSION(7, 0, 0): 2353 case IP_VERSION(7, 0, 1): 2354 amdgpu_device_ip_block_add(adev, &sdma_v7_0_ip_block); 2355 break; 2356 default: 2357 dev_err(adev->dev, 2358 "Failed to add sdma ip block(SDMA0_HWIP:0x%x)\n", 2359 amdgpu_ip_version(adev, SDMA0_HWIP, 0)); 2360 return -EINVAL; 2361 } 2362 return 0; 2363 } 2364 2365 static int amdgpu_discovery_set_mm_ip_blocks(struct amdgpu_device *adev) 2366 { 2367 if (amdgpu_ip_version(adev, VCE_HWIP, 0)) { 2368 switch (amdgpu_ip_version(adev, UVD_HWIP, 0)) { 2369 case IP_VERSION(7, 0, 0): 2370 case IP_VERSION(7, 2, 0): 2371 /* UVD is not supported on vega20 SR-IOV */ 2372 if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev))) 2373 amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block); 2374 break; 2375 default: 2376 dev_err(adev->dev, 2377 "Failed to add uvd v7 ip block(UVD_HWIP:0x%x)\n", 2378 amdgpu_ip_version(adev, UVD_HWIP, 0)); 2379 return -EINVAL; 2380 } 2381 switch (amdgpu_ip_version(adev, VCE_HWIP, 0)) { 2382 case IP_VERSION(4, 0, 0): 2383 case IP_VERSION(4, 1, 0): 2384 /* VCE is not supported on vega20 SR-IOV */ 2385 if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev))) 2386 amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block); 2387 break; 2388 default: 2389 dev_err(adev->dev, 2390 "Failed to add VCE v4 ip block(VCE_HWIP:0x%x)\n", 2391 amdgpu_ip_version(adev, VCE_HWIP, 0)); 2392 return -EINVAL; 2393 } 2394 } else { 2395 switch (amdgpu_ip_version(adev, UVD_HWIP, 0)) { 2396 case IP_VERSION(1, 0, 0): 2397 case IP_VERSION(1, 0, 1): 2398 amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block); 2399 break; 2400 case IP_VERSION(2, 0, 0): 2401 case IP_VERSION(2, 0, 2): 2402 case IP_VERSION(2, 2, 0): 2403 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block); 2404 if (!amdgpu_sriov_vf(adev)) 2405 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block); 2406 break; 2407 case IP_VERSION(2, 0, 3): 2408 break; 2409 case IP_VERSION(2, 5, 0): 2410 amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block); 2411 amdgpu_device_ip_block_add(adev, &jpeg_v2_5_ip_block); 2412 break; 2413 case IP_VERSION(2, 6, 0): 2414 amdgpu_device_ip_block_add(adev, &vcn_v2_6_ip_block); 2415 amdgpu_device_ip_block_add(adev, &jpeg_v2_6_ip_block); 2416 break; 2417 case IP_VERSION(3, 0, 0): 2418 case IP_VERSION(3, 0, 16): 2419 case IP_VERSION(3, 1, 1): 2420 case IP_VERSION(3, 1, 2): 2421 case IP_VERSION(3, 0, 2): 2422 amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block); 2423 if (!amdgpu_sriov_vf(adev)) 2424 amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block); 2425 break; 2426 case IP_VERSION(3, 0, 33): 2427 amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block); 2428 break; 2429 case IP_VERSION(4, 0, 0): 2430 case IP_VERSION(4, 0, 2): 2431 case IP_VERSION(4, 0, 4): 2432 amdgpu_device_ip_block_add(adev, &vcn_v4_0_ip_block); 2433 amdgpu_device_ip_block_add(adev, &jpeg_v4_0_ip_block); 2434 break; 2435 case IP_VERSION(4, 0, 3): 2436 amdgpu_device_ip_block_add(adev, &vcn_v4_0_3_ip_block); 2437 amdgpu_device_ip_block_add(adev, &jpeg_v4_0_3_ip_block); 2438 break; 2439 case IP_VERSION(4, 0, 5): 2440 case IP_VERSION(4, 0, 6): 2441 amdgpu_device_ip_block_add(adev, &vcn_v4_0_5_ip_block); 2442 amdgpu_device_ip_block_add(adev, &jpeg_v4_0_5_ip_block); 2443 break; 2444 case IP_VERSION(5, 0, 0): 2445 amdgpu_device_ip_block_add(adev, &vcn_v5_0_0_ip_block); 2446 amdgpu_device_ip_block_add(adev, &jpeg_v5_0_0_ip_block); 2447 break; 2448 case IP_VERSION(5, 0, 1): 2449 amdgpu_device_ip_block_add(adev, &vcn_v5_0_1_ip_block); 2450 amdgpu_device_ip_block_add(adev, &jpeg_v5_0_1_ip_block); 2451 break; 2452 default: 2453 dev_err(adev->dev, 2454 "Failed to add vcn/jpeg ip block(UVD_HWIP:0x%x)\n", 2455 amdgpu_ip_version(adev, UVD_HWIP, 0)); 2456 return -EINVAL; 2457 } 2458 } 2459 return 0; 2460 } 2461 2462 static int amdgpu_discovery_set_mes_ip_blocks(struct amdgpu_device *adev) 2463 { 2464 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 2465 case IP_VERSION(11, 0, 0): 2466 case IP_VERSION(11, 0, 1): 2467 case IP_VERSION(11, 0, 2): 2468 case IP_VERSION(11, 0, 3): 2469 case IP_VERSION(11, 0, 4): 2470 case IP_VERSION(11, 5, 0): 2471 case IP_VERSION(11, 5, 1): 2472 case IP_VERSION(11, 5, 2): 2473 case IP_VERSION(11, 5, 3): 2474 amdgpu_device_ip_block_add(adev, &mes_v11_0_ip_block); 2475 adev->enable_mes = true; 2476 adev->enable_mes_kiq = true; 2477 break; 2478 case IP_VERSION(12, 0, 0): 2479 case IP_VERSION(12, 0, 1): 2480 amdgpu_device_ip_block_add(adev, &mes_v12_0_ip_block); 2481 adev->enable_mes = true; 2482 adev->enable_mes_kiq = true; 2483 if (amdgpu_uni_mes) 2484 adev->enable_uni_mes = true; 2485 break; 2486 default: 2487 break; 2488 } 2489 return 0; 2490 } 2491 2492 static void amdgpu_discovery_init_soc_config(struct amdgpu_device *adev) 2493 { 2494 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 2495 case IP_VERSION(9, 4, 3): 2496 case IP_VERSION(9, 4, 4): 2497 case IP_VERSION(9, 5, 0): 2498 aqua_vanjaram_init_soc_config(adev); 2499 break; 2500 default: 2501 break; 2502 } 2503 } 2504 2505 static int amdgpu_discovery_set_vpe_ip_blocks(struct amdgpu_device *adev) 2506 { 2507 switch (amdgpu_ip_version(adev, VPE_HWIP, 0)) { 2508 case IP_VERSION(6, 1, 0): 2509 case IP_VERSION(6, 1, 1): 2510 case IP_VERSION(6, 1, 3): 2511 amdgpu_device_ip_block_add(adev, &vpe_v6_1_ip_block); 2512 break; 2513 default: 2514 break; 2515 } 2516 2517 return 0; 2518 } 2519 2520 static int amdgpu_discovery_set_umsch_mm_ip_blocks(struct amdgpu_device *adev) 2521 { 2522 switch (amdgpu_ip_version(adev, VCN_HWIP, 0)) { 2523 case IP_VERSION(4, 0, 5): 2524 case IP_VERSION(4, 0, 6): 2525 if (amdgpu_umsch_mm & 0x1) { 2526 amdgpu_device_ip_block_add(adev, &umsch_mm_v4_0_ip_block); 2527 adev->enable_umsch_mm = true; 2528 } 2529 break; 2530 default: 2531 break; 2532 } 2533 2534 return 0; 2535 } 2536 2537 static int amdgpu_discovery_set_isp_ip_blocks(struct amdgpu_device *adev) 2538 { 2539 #if defined(CONFIG_DRM_AMD_ISP) 2540 switch (amdgpu_ip_version(adev, ISP_HWIP, 0)) { 2541 case IP_VERSION(4, 1, 0): 2542 amdgpu_device_ip_block_add(adev, &isp_v4_1_0_ip_block); 2543 break; 2544 case IP_VERSION(4, 1, 1): 2545 amdgpu_device_ip_block_add(adev, &isp_v4_1_1_ip_block); 2546 break; 2547 default: 2548 break; 2549 } 2550 #endif 2551 2552 return 0; 2553 } 2554 2555 int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev) 2556 { 2557 int r; 2558 2559 switch (adev->asic_type) { 2560 case CHIP_VEGA10: 2561 /* This is not fatal. We only need the discovery 2562 * binary for sysfs. We don't need it for a 2563 * functional system. 2564 */ 2565 amdgpu_discovery_init(adev); 2566 vega10_reg_base_init(adev); 2567 adev->sdma.num_instances = 2; 2568 adev->gmc.num_umc = 4; 2569 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 0, 0); 2570 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 0, 0); 2571 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 0, 0); 2572 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 0, 0); 2573 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 0, 0); 2574 adev->ip_versions[SDMA1_HWIP][0] = IP_VERSION(4, 0, 0); 2575 adev->ip_versions[DF_HWIP][0] = IP_VERSION(2, 1, 0); 2576 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(6, 1, 0); 2577 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 0, 0); 2578 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(9, 0, 0); 2579 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(9, 0, 0); 2580 adev->ip_versions[THM_HWIP][0] = IP_VERSION(9, 0, 0); 2581 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(9, 0, 0); 2582 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 0, 1); 2583 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(7, 0, 0); 2584 adev->ip_versions[VCE_HWIP][0] = IP_VERSION(4, 0, 0); 2585 adev->ip_versions[DCI_HWIP][0] = IP_VERSION(12, 0, 0); 2586 break; 2587 case CHIP_VEGA12: 2588 /* This is not fatal. We only need the discovery 2589 * binary for sysfs. We don't need it for a 2590 * functional system. 2591 */ 2592 amdgpu_discovery_init(adev); 2593 vega10_reg_base_init(adev); 2594 adev->sdma.num_instances = 2; 2595 adev->gmc.num_umc = 4; 2596 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 3, 0); 2597 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 3, 0); 2598 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 0, 1); 2599 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 0, 1); 2600 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 0, 1); 2601 adev->ip_versions[SDMA1_HWIP][0] = IP_VERSION(4, 0, 1); 2602 adev->ip_versions[DF_HWIP][0] = IP_VERSION(2, 5, 0); 2603 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(6, 2, 0); 2604 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 1, 0); 2605 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(9, 0, 0); 2606 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(9, 0, 0); 2607 adev->ip_versions[THM_HWIP][0] = IP_VERSION(9, 0, 0); 2608 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(9, 0, 1); 2609 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 2, 1); 2610 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(7, 0, 0); 2611 adev->ip_versions[VCE_HWIP][0] = IP_VERSION(4, 0, 0); 2612 adev->ip_versions[DCI_HWIP][0] = IP_VERSION(12, 0, 1); 2613 break; 2614 case CHIP_RAVEN: 2615 /* This is not fatal. We only need the discovery 2616 * binary for sysfs. We don't need it for a 2617 * functional system. 2618 */ 2619 amdgpu_discovery_init(adev); 2620 vega10_reg_base_init(adev); 2621 adev->sdma.num_instances = 1; 2622 adev->vcn.num_vcn_inst = 1; 2623 adev->gmc.num_umc = 2; 2624 if (adev->apu_flags & AMD_APU_IS_RAVEN2) { 2625 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 2, 0); 2626 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 2, 0); 2627 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 1, 1); 2628 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 1, 1); 2629 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 1, 1); 2630 adev->ip_versions[DF_HWIP][0] = IP_VERSION(2, 1, 1); 2631 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 0, 1); 2632 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(7, 5, 0); 2633 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(10, 0, 1); 2634 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(10, 0, 1); 2635 adev->ip_versions[THM_HWIP][0] = IP_VERSION(10, 1, 0); 2636 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(10, 0, 1); 2637 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 2, 2); 2638 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(1, 0, 1); 2639 adev->ip_versions[DCE_HWIP][0] = IP_VERSION(1, 0, 1); 2640 adev->ip_versions[ISP_HWIP][0] = IP_VERSION(2, 0, 0); 2641 } else { 2642 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 1, 0); 2643 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 1, 0); 2644 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 1, 0); 2645 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 1, 0); 2646 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 1, 0); 2647 adev->ip_versions[DF_HWIP][0] = IP_VERSION(2, 1, 0); 2648 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 0, 0); 2649 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(7, 0, 0); 2650 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(10, 0, 0); 2651 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(10, 0, 0); 2652 adev->ip_versions[THM_HWIP][0] = IP_VERSION(10, 0, 0); 2653 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(10, 0, 0); 2654 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 1, 0); 2655 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(1, 0, 0); 2656 adev->ip_versions[DCE_HWIP][0] = IP_VERSION(1, 0, 0); 2657 adev->ip_versions[ISP_HWIP][0] = IP_VERSION(2, 0, 0); 2658 } 2659 break; 2660 case CHIP_VEGA20: 2661 /* This is not fatal. We only need the discovery 2662 * binary for sysfs. We don't need it for a 2663 * functional system. 2664 */ 2665 amdgpu_discovery_init(adev); 2666 vega20_reg_base_init(adev); 2667 adev->sdma.num_instances = 2; 2668 adev->gmc.num_umc = 8; 2669 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 4, 0); 2670 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 4, 0); 2671 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 2, 0); 2672 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 2, 0); 2673 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 2, 0); 2674 adev->ip_versions[SDMA1_HWIP][0] = IP_VERSION(4, 2, 0); 2675 adev->ip_versions[DF_HWIP][0] = IP_VERSION(3, 6, 0); 2676 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 4, 0); 2677 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 1, 1); 2678 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(11, 0, 2); 2679 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(11, 0, 2); 2680 adev->ip_versions[THM_HWIP][0] = IP_VERSION(11, 0, 2); 2681 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(11, 0, 2); 2682 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 4, 0); 2683 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(7, 2, 0); 2684 adev->ip_versions[UVD_HWIP][1] = IP_VERSION(7, 2, 0); 2685 adev->ip_versions[VCE_HWIP][0] = IP_VERSION(4, 1, 0); 2686 adev->ip_versions[DCI_HWIP][0] = IP_VERSION(12, 1, 0); 2687 break; 2688 case CHIP_ARCTURUS: 2689 /* This is not fatal. We only need the discovery 2690 * binary for sysfs. We don't need it for a 2691 * functional system. 2692 */ 2693 amdgpu_discovery_init(adev); 2694 arct_reg_base_init(adev); 2695 adev->sdma.num_instances = 8; 2696 adev->vcn.num_vcn_inst = 2; 2697 adev->gmc.num_umc = 8; 2698 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 4, 1); 2699 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 4, 1); 2700 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 2, 1); 2701 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 2, 1); 2702 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 2, 2); 2703 adev->ip_versions[SDMA1_HWIP][0] = IP_VERSION(4, 2, 2); 2704 adev->ip_versions[SDMA1_HWIP][1] = IP_VERSION(4, 2, 2); 2705 adev->ip_versions[SDMA1_HWIP][2] = IP_VERSION(4, 2, 2); 2706 adev->ip_versions[SDMA1_HWIP][3] = IP_VERSION(4, 2, 2); 2707 adev->ip_versions[SDMA1_HWIP][4] = IP_VERSION(4, 2, 2); 2708 adev->ip_versions[SDMA1_HWIP][5] = IP_VERSION(4, 2, 2); 2709 adev->ip_versions[SDMA1_HWIP][6] = IP_VERSION(4, 2, 2); 2710 adev->ip_versions[DF_HWIP][0] = IP_VERSION(3, 6, 1); 2711 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 4, 1); 2712 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 1, 2); 2713 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(11, 0, 4); 2714 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(11, 0, 2); 2715 adev->ip_versions[THM_HWIP][0] = IP_VERSION(11, 0, 3); 2716 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(11, 0, 3); 2717 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 4, 1); 2718 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(2, 5, 0); 2719 adev->ip_versions[UVD_HWIP][1] = IP_VERSION(2, 5, 0); 2720 break; 2721 case CHIP_ALDEBARAN: 2722 /* This is not fatal. We only need the discovery 2723 * binary for sysfs. We don't need it for a 2724 * functional system. 2725 */ 2726 amdgpu_discovery_init(adev); 2727 aldebaran_reg_base_init(adev); 2728 adev->sdma.num_instances = 5; 2729 adev->vcn.num_vcn_inst = 2; 2730 adev->gmc.num_umc = 4; 2731 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(9, 4, 2); 2732 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(9, 4, 2); 2733 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(4, 4, 0); 2734 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(4, 4, 0); 2735 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(4, 4, 0); 2736 adev->ip_versions[SDMA0_HWIP][1] = IP_VERSION(4, 4, 0); 2737 adev->ip_versions[SDMA0_HWIP][2] = IP_VERSION(4, 4, 0); 2738 adev->ip_versions[SDMA0_HWIP][3] = IP_VERSION(4, 4, 0); 2739 adev->ip_versions[SDMA0_HWIP][4] = IP_VERSION(4, 4, 0); 2740 adev->ip_versions[DF_HWIP][0] = IP_VERSION(3, 6, 2); 2741 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(7, 4, 4); 2742 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(6, 7, 0); 2743 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(13, 0, 2); 2744 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(13, 0, 2); 2745 adev->ip_versions[THM_HWIP][0] = IP_VERSION(13, 0, 2); 2746 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(13, 0, 2); 2747 adev->ip_versions[GC_HWIP][0] = IP_VERSION(9, 4, 2); 2748 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(2, 6, 0); 2749 adev->ip_versions[UVD_HWIP][1] = IP_VERSION(2, 6, 0); 2750 adev->ip_versions[XGMI_HWIP][0] = IP_VERSION(6, 1, 0); 2751 break; 2752 case CHIP_CYAN_SKILLFISH: 2753 if (adev->apu_flags & AMD_APU_IS_CYAN_SKILLFISH2) { 2754 r = amdgpu_discovery_reg_base_init(adev); 2755 if (r) 2756 return -EINVAL; 2757 2758 amdgpu_discovery_harvest_ip(adev); 2759 amdgpu_discovery_get_gfx_info(adev); 2760 amdgpu_discovery_get_mall_info(adev); 2761 amdgpu_discovery_get_vcn_info(adev); 2762 } else { 2763 cyan_skillfish_reg_base_init(adev); 2764 adev->sdma.num_instances = 2; 2765 adev->ip_versions[MMHUB_HWIP][0] = IP_VERSION(2, 0, 3); 2766 adev->ip_versions[ATHUB_HWIP][0] = IP_VERSION(2, 0, 3); 2767 adev->ip_versions[OSSSYS_HWIP][0] = IP_VERSION(5, 0, 1); 2768 adev->ip_versions[HDP_HWIP][0] = IP_VERSION(5, 0, 1); 2769 adev->ip_versions[SDMA0_HWIP][0] = IP_VERSION(5, 0, 1); 2770 adev->ip_versions[SDMA1_HWIP][1] = IP_VERSION(5, 0, 1); 2771 adev->ip_versions[DF_HWIP][0] = IP_VERSION(3, 5, 0); 2772 adev->ip_versions[NBIO_HWIP][0] = IP_VERSION(2, 1, 1); 2773 adev->ip_versions[UMC_HWIP][0] = IP_VERSION(8, 1, 1); 2774 adev->ip_versions[MP0_HWIP][0] = IP_VERSION(11, 0, 8); 2775 adev->ip_versions[MP1_HWIP][0] = IP_VERSION(11, 0, 8); 2776 adev->ip_versions[THM_HWIP][0] = IP_VERSION(11, 0, 1); 2777 adev->ip_versions[SMUIO_HWIP][0] = IP_VERSION(11, 0, 8); 2778 adev->ip_versions[GC_HWIP][0] = IP_VERSION(10, 1, 3); 2779 adev->ip_versions[UVD_HWIP][0] = IP_VERSION(2, 0, 3); 2780 } 2781 break; 2782 default: 2783 r = amdgpu_discovery_reg_base_init(adev); 2784 if (r) { 2785 drm_err(&adev->ddev, "discovery failed: %d\n", r); 2786 return r; 2787 } 2788 2789 amdgpu_discovery_harvest_ip(adev); 2790 amdgpu_discovery_get_gfx_info(adev); 2791 amdgpu_discovery_get_mall_info(adev); 2792 amdgpu_discovery_get_vcn_info(adev); 2793 break; 2794 } 2795 2796 amdgpu_discovery_init_soc_config(adev); 2797 amdgpu_discovery_sysfs_init(adev); 2798 2799 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 2800 case IP_VERSION(9, 0, 1): 2801 case IP_VERSION(9, 2, 1): 2802 case IP_VERSION(9, 4, 0): 2803 case IP_VERSION(9, 4, 1): 2804 case IP_VERSION(9, 4, 2): 2805 case IP_VERSION(9, 4, 3): 2806 case IP_VERSION(9, 4, 4): 2807 case IP_VERSION(9, 5, 0): 2808 adev->family = AMDGPU_FAMILY_AI; 2809 break; 2810 case IP_VERSION(9, 1, 0): 2811 case IP_VERSION(9, 2, 2): 2812 case IP_VERSION(9, 3, 0): 2813 adev->family = AMDGPU_FAMILY_RV; 2814 break; 2815 case IP_VERSION(10, 1, 10): 2816 case IP_VERSION(10, 1, 1): 2817 case IP_VERSION(10, 1, 2): 2818 case IP_VERSION(10, 1, 3): 2819 case IP_VERSION(10, 1, 4): 2820 case IP_VERSION(10, 3, 0): 2821 case IP_VERSION(10, 3, 2): 2822 case IP_VERSION(10, 3, 4): 2823 case IP_VERSION(10, 3, 5): 2824 adev->family = AMDGPU_FAMILY_NV; 2825 break; 2826 case IP_VERSION(10, 3, 1): 2827 adev->family = AMDGPU_FAMILY_VGH; 2828 adev->apu_flags |= AMD_APU_IS_VANGOGH; 2829 break; 2830 case IP_VERSION(10, 3, 3): 2831 adev->family = AMDGPU_FAMILY_YC; 2832 break; 2833 case IP_VERSION(10, 3, 6): 2834 adev->family = AMDGPU_FAMILY_GC_10_3_6; 2835 break; 2836 case IP_VERSION(10, 3, 7): 2837 adev->family = AMDGPU_FAMILY_GC_10_3_7; 2838 break; 2839 case IP_VERSION(11, 0, 0): 2840 case IP_VERSION(11, 0, 2): 2841 case IP_VERSION(11, 0, 3): 2842 adev->family = AMDGPU_FAMILY_GC_11_0_0; 2843 break; 2844 case IP_VERSION(11, 0, 1): 2845 case IP_VERSION(11, 0, 4): 2846 adev->family = AMDGPU_FAMILY_GC_11_0_1; 2847 break; 2848 case IP_VERSION(11, 5, 0): 2849 case IP_VERSION(11, 5, 1): 2850 case IP_VERSION(11, 5, 2): 2851 case IP_VERSION(11, 5, 3): 2852 adev->family = AMDGPU_FAMILY_GC_11_5_0; 2853 break; 2854 case IP_VERSION(12, 0, 0): 2855 case IP_VERSION(12, 0, 1): 2856 adev->family = AMDGPU_FAMILY_GC_12_0_0; 2857 break; 2858 default: 2859 return -EINVAL; 2860 } 2861 2862 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 2863 case IP_VERSION(9, 1, 0): 2864 case IP_VERSION(9, 2, 2): 2865 case IP_VERSION(9, 3, 0): 2866 case IP_VERSION(10, 1, 3): 2867 case IP_VERSION(10, 1, 4): 2868 case IP_VERSION(10, 3, 1): 2869 case IP_VERSION(10, 3, 3): 2870 case IP_VERSION(10, 3, 6): 2871 case IP_VERSION(10, 3, 7): 2872 case IP_VERSION(11, 0, 1): 2873 case IP_VERSION(11, 0, 4): 2874 case IP_VERSION(11, 5, 0): 2875 case IP_VERSION(11, 5, 1): 2876 case IP_VERSION(11, 5, 2): 2877 case IP_VERSION(11, 5, 3): 2878 adev->flags |= AMD_IS_APU; 2879 break; 2880 default: 2881 break; 2882 } 2883 2884 /* set NBIO version */ 2885 switch (amdgpu_ip_version(adev, NBIO_HWIP, 0)) { 2886 case IP_VERSION(6, 1, 0): 2887 case IP_VERSION(6, 2, 0): 2888 adev->nbio.funcs = &nbio_v6_1_funcs; 2889 adev->nbio.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg; 2890 break; 2891 case IP_VERSION(7, 0, 0): 2892 case IP_VERSION(7, 0, 1): 2893 case IP_VERSION(2, 5, 0): 2894 adev->nbio.funcs = &nbio_v7_0_funcs; 2895 adev->nbio.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg; 2896 break; 2897 case IP_VERSION(7, 4, 0): 2898 case IP_VERSION(7, 4, 1): 2899 case IP_VERSION(7, 4, 4): 2900 adev->nbio.funcs = &nbio_v7_4_funcs; 2901 adev->nbio.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg; 2902 break; 2903 case IP_VERSION(7, 9, 0): 2904 case IP_VERSION(7, 9, 1): 2905 adev->nbio.funcs = &nbio_v7_9_funcs; 2906 adev->nbio.hdp_flush_reg = &nbio_v7_9_hdp_flush_reg; 2907 break; 2908 case IP_VERSION(7, 11, 0): 2909 case IP_VERSION(7, 11, 1): 2910 case IP_VERSION(7, 11, 2): 2911 case IP_VERSION(7, 11, 3): 2912 adev->nbio.funcs = &nbio_v7_11_funcs; 2913 adev->nbio.hdp_flush_reg = &nbio_v7_11_hdp_flush_reg; 2914 break; 2915 case IP_VERSION(7, 2, 0): 2916 case IP_VERSION(7, 2, 1): 2917 case IP_VERSION(7, 3, 0): 2918 case IP_VERSION(7, 5, 0): 2919 case IP_VERSION(7, 5, 1): 2920 adev->nbio.funcs = &nbio_v7_2_funcs; 2921 adev->nbio.hdp_flush_reg = &nbio_v7_2_hdp_flush_reg; 2922 break; 2923 case IP_VERSION(2, 1, 1): 2924 case IP_VERSION(2, 3, 0): 2925 case IP_VERSION(2, 3, 1): 2926 case IP_VERSION(2, 3, 2): 2927 case IP_VERSION(3, 3, 0): 2928 case IP_VERSION(3, 3, 1): 2929 case IP_VERSION(3, 3, 2): 2930 case IP_VERSION(3, 3, 3): 2931 adev->nbio.funcs = &nbio_v2_3_funcs; 2932 adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg; 2933 break; 2934 case IP_VERSION(4, 3, 0): 2935 case IP_VERSION(4, 3, 1): 2936 if (amdgpu_sriov_vf(adev)) 2937 adev->nbio.funcs = &nbio_v4_3_sriov_funcs; 2938 else 2939 adev->nbio.funcs = &nbio_v4_3_funcs; 2940 adev->nbio.hdp_flush_reg = &nbio_v4_3_hdp_flush_reg; 2941 break; 2942 case IP_VERSION(7, 7, 0): 2943 case IP_VERSION(7, 7, 1): 2944 adev->nbio.funcs = &nbio_v7_7_funcs; 2945 adev->nbio.hdp_flush_reg = &nbio_v7_7_hdp_flush_reg; 2946 break; 2947 case IP_VERSION(6, 3, 1): 2948 adev->nbio.funcs = &nbif_v6_3_1_funcs; 2949 adev->nbio.hdp_flush_reg = &nbif_v6_3_1_hdp_flush_reg; 2950 break; 2951 default: 2952 break; 2953 } 2954 2955 switch (amdgpu_ip_version(adev, HDP_HWIP, 0)) { 2956 case IP_VERSION(4, 0, 0): 2957 case IP_VERSION(4, 0, 1): 2958 case IP_VERSION(4, 1, 0): 2959 case IP_VERSION(4, 1, 1): 2960 case IP_VERSION(4, 1, 2): 2961 case IP_VERSION(4, 2, 0): 2962 case IP_VERSION(4, 2, 1): 2963 case IP_VERSION(4, 4, 0): 2964 case IP_VERSION(4, 4, 2): 2965 case IP_VERSION(4, 4, 5): 2966 adev->hdp.funcs = &hdp_v4_0_funcs; 2967 break; 2968 case IP_VERSION(5, 0, 0): 2969 case IP_VERSION(5, 0, 1): 2970 case IP_VERSION(5, 0, 2): 2971 case IP_VERSION(5, 0, 3): 2972 case IP_VERSION(5, 0, 4): 2973 case IP_VERSION(5, 2, 0): 2974 adev->hdp.funcs = &hdp_v5_0_funcs; 2975 break; 2976 case IP_VERSION(5, 2, 1): 2977 adev->hdp.funcs = &hdp_v5_2_funcs; 2978 break; 2979 case IP_VERSION(6, 0, 0): 2980 case IP_VERSION(6, 0, 1): 2981 case IP_VERSION(6, 1, 0): 2982 adev->hdp.funcs = &hdp_v6_0_funcs; 2983 break; 2984 case IP_VERSION(7, 0, 0): 2985 adev->hdp.funcs = &hdp_v7_0_funcs; 2986 break; 2987 default: 2988 break; 2989 } 2990 2991 switch (amdgpu_ip_version(adev, DF_HWIP, 0)) { 2992 case IP_VERSION(3, 6, 0): 2993 case IP_VERSION(3, 6, 1): 2994 case IP_VERSION(3, 6, 2): 2995 adev->df.funcs = &df_v3_6_funcs; 2996 break; 2997 case IP_VERSION(2, 1, 0): 2998 case IP_VERSION(2, 1, 1): 2999 case IP_VERSION(2, 5, 0): 3000 case IP_VERSION(3, 5, 1): 3001 case IP_VERSION(3, 5, 2): 3002 adev->df.funcs = &df_v1_7_funcs; 3003 break; 3004 case IP_VERSION(4, 3, 0): 3005 adev->df.funcs = &df_v4_3_funcs; 3006 break; 3007 case IP_VERSION(4, 6, 2): 3008 adev->df.funcs = &df_v4_6_2_funcs; 3009 break; 3010 case IP_VERSION(4, 15, 0): 3011 case IP_VERSION(4, 15, 1): 3012 adev->df.funcs = &df_v4_15_funcs; 3013 break; 3014 default: 3015 break; 3016 } 3017 3018 switch (amdgpu_ip_version(adev, SMUIO_HWIP, 0)) { 3019 case IP_VERSION(9, 0, 0): 3020 case IP_VERSION(9, 0, 1): 3021 case IP_VERSION(10, 0, 0): 3022 case IP_VERSION(10, 0, 1): 3023 case IP_VERSION(10, 0, 2): 3024 adev->smuio.funcs = &smuio_v9_0_funcs; 3025 break; 3026 case IP_VERSION(11, 0, 0): 3027 case IP_VERSION(11, 0, 2): 3028 case IP_VERSION(11, 0, 3): 3029 case IP_VERSION(11, 0, 4): 3030 case IP_VERSION(11, 0, 7): 3031 case IP_VERSION(11, 0, 8): 3032 adev->smuio.funcs = &smuio_v11_0_funcs; 3033 break; 3034 case IP_VERSION(11, 0, 6): 3035 case IP_VERSION(11, 0, 10): 3036 case IP_VERSION(11, 0, 11): 3037 case IP_VERSION(11, 5, 0): 3038 case IP_VERSION(11, 5, 2): 3039 case IP_VERSION(13, 0, 1): 3040 case IP_VERSION(13, 0, 9): 3041 case IP_VERSION(13, 0, 10): 3042 adev->smuio.funcs = &smuio_v11_0_6_funcs; 3043 break; 3044 case IP_VERSION(13, 0, 2): 3045 adev->smuio.funcs = &smuio_v13_0_funcs; 3046 break; 3047 case IP_VERSION(13, 0, 3): 3048 case IP_VERSION(13, 0, 11): 3049 adev->smuio.funcs = &smuio_v13_0_3_funcs; 3050 if (adev->smuio.funcs->get_pkg_type(adev) == AMDGPU_PKG_TYPE_APU) { 3051 adev->flags |= AMD_IS_APU; 3052 } 3053 break; 3054 case IP_VERSION(13, 0, 6): 3055 case IP_VERSION(13, 0, 8): 3056 case IP_VERSION(14, 0, 0): 3057 case IP_VERSION(14, 0, 1): 3058 adev->smuio.funcs = &smuio_v13_0_6_funcs; 3059 break; 3060 case IP_VERSION(14, 0, 2): 3061 adev->smuio.funcs = &smuio_v14_0_2_funcs; 3062 break; 3063 default: 3064 break; 3065 } 3066 3067 switch (amdgpu_ip_version(adev, LSDMA_HWIP, 0)) { 3068 case IP_VERSION(6, 0, 0): 3069 case IP_VERSION(6, 0, 1): 3070 case IP_VERSION(6, 0, 2): 3071 case IP_VERSION(6, 0, 3): 3072 adev->lsdma.funcs = &lsdma_v6_0_funcs; 3073 break; 3074 case IP_VERSION(7, 0, 0): 3075 case IP_VERSION(7, 0, 1): 3076 adev->lsdma.funcs = &lsdma_v7_0_funcs; 3077 break; 3078 default: 3079 break; 3080 } 3081 3082 r = amdgpu_discovery_set_common_ip_blocks(adev); 3083 if (r) 3084 return r; 3085 3086 r = amdgpu_discovery_set_gmc_ip_blocks(adev); 3087 if (r) 3088 return r; 3089 3090 /* For SR-IOV, PSP needs to be initialized before IH */ 3091 if (amdgpu_sriov_vf(adev)) { 3092 r = amdgpu_discovery_set_psp_ip_blocks(adev); 3093 if (r) 3094 return r; 3095 r = amdgpu_discovery_set_ih_ip_blocks(adev); 3096 if (r) 3097 return r; 3098 } else { 3099 r = amdgpu_discovery_set_ih_ip_blocks(adev); 3100 if (r) 3101 return r; 3102 3103 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) { 3104 r = amdgpu_discovery_set_psp_ip_blocks(adev); 3105 if (r) 3106 return r; 3107 } 3108 } 3109 3110 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) { 3111 r = amdgpu_discovery_set_smu_ip_blocks(adev); 3112 if (r) 3113 return r; 3114 } 3115 3116 r = amdgpu_discovery_set_display_ip_blocks(adev); 3117 if (r) 3118 return r; 3119 3120 r = amdgpu_discovery_set_gc_ip_blocks(adev); 3121 if (r) 3122 return r; 3123 3124 r = amdgpu_discovery_set_sdma_ip_blocks(adev); 3125 if (r) 3126 return r; 3127 3128 if ((adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT && 3129 !amdgpu_sriov_vf(adev)) || 3130 (adev->firmware.load_type == AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO && amdgpu_dpm == 1)) { 3131 r = amdgpu_discovery_set_smu_ip_blocks(adev); 3132 if (r) 3133 return r; 3134 } 3135 3136 r = amdgpu_discovery_set_mm_ip_blocks(adev); 3137 if (r) 3138 return r; 3139 3140 r = amdgpu_discovery_set_mes_ip_blocks(adev); 3141 if (r) 3142 return r; 3143 3144 r = amdgpu_discovery_set_vpe_ip_blocks(adev); 3145 if (r) 3146 return r; 3147 3148 r = amdgpu_discovery_set_umsch_mm_ip_blocks(adev); 3149 if (r) 3150 return r; 3151 3152 r = amdgpu_discovery_set_isp_ip_blocks(adev); 3153 if (r) 3154 return r; 3155 return 0; 3156 } 3157 3158