Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: use new flag to handle different firmware loading method

This patch introduces a new flag named "amdgpu_firmware_load_type" to
handle different firmware loading method. Since Vega10, there are
three ways to load firmware. It would be better to use a flag and a
fw_load_type kernel parameter to configure it.

Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Huang Rui and committed by
Alex Deucher
e635ee07 70170d14

+90 -20
+8 -2
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 81 81 extern int amdgpu_msi; 82 82 extern int amdgpu_lockup_timeout; 83 83 extern int amdgpu_dpm; 84 - extern int amdgpu_smc_load_fw; 84 + extern int amdgpu_fw_load_type; 85 85 extern int amdgpu_aspm; 86 86 extern int amdgpu_runtime_pm; 87 87 extern unsigned amdgpu_ip_block_mask; ··· 1063 1063 /* 1064 1064 * Firmware 1065 1065 */ 1066 + enum amdgpu_firmware_load_type { 1067 + AMDGPU_FW_LOAD_DIRECT = 0, 1068 + AMDGPU_FW_LOAD_SMU, 1069 + AMDGPU_FW_LOAD_PSP, 1070 + }; 1071 + 1066 1072 struct amdgpu_firmware { 1067 1073 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM]; 1068 - bool smu_load; 1074 + enum amdgpu_firmware_load_type load_type; 1069 1075 struct amdgpu_bo *fw_buf; 1070 1076 unsigned int fw_size; 1071 1077 };
+3 -3
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
··· 80 80 int amdgpu_msi = -1; 81 81 int amdgpu_lockup_timeout = 0; 82 82 int amdgpu_dpm = -1; 83 - int amdgpu_smc_load_fw = 1; 83 + int amdgpu_fw_load_type = -1; 84 84 int amdgpu_aspm = -1; 85 85 int amdgpu_runtime_pm = -1; 86 86 unsigned amdgpu_ip_block_mask = 0xffffffff; ··· 140 140 MODULE_PARM_DESC(dpm, "DPM support (1 = enable, 0 = disable, -1 = auto)"); 141 141 module_param_named(dpm, amdgpu_dpm, int, 0444); 142 142 143 - MODULE_PARM_DESC(smc_load_fw, "SMC firmware loading(1 = enable, 0 = disable)"); 144 - module_param_named(smc_load_fw, amdgpu_smc_load_fw, int, 0444); 143 + MODULE_PARM_DESC(fw_load_type, "firmware loading type (0 = direct, 1 = SMU, 2 = PSP, -1 = auto)"); 144 + module_param_named(fw_load_type, amdgpu_fw_load_type, int, 0444); 145 145 146 146 MODULE_PARM_DESC(aspm, "ASPM support (1 = enable, 0 = disable, -1 = auto)"); 147 147 module_param_named(aspm, amdgpu_aspm, int, 0444);
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
··· 163 163 int ret = 0; 164 164 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 165 165 166 - if (adev->pp_enabled && adev->firmware.smu_load) 166 + if (adev->pp_enabled && adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) 167 167 amdgpu_ucode_init_bo(adev); 168 168 169 169 if (adev->powerplay.ip_funcs->hw_init) ··· 190 190 ret = adev->powerplay.ip_funcs->hw_fini( 191 191 adev->powerplay.pp_handle); 192 192 193 - if (adev->pp_enabled && adev->firmware.smu_load) 193 + if (adev->pp_enabled && adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) 194 194 amdgpu_ucode_fini_bo(adev); 195 195 196 196 return ret;
+63 -4
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
··· 217 217 return true; 218 218 } 219 219 220 + enum amdgpu_firmware_load_type 221 + amdgpu_ucode_get_load_type(struct amdgpu_device *adev, int load_type) 222 + { 223 + switch (adev->asic_type) { 224 + #ifdef CONFIG_DRM_AMDGPU_SI 225 + case CHIP_TAHITI: 226 + case CHIP_PITCAIRN: 227 + case CHIP_VERDE: 228 + case CHIP_OLAND: 229 + return AMDGPU_FW_LOAD_DIRECT; 230 + #endif 231 + #ifdef CONFIG_DRM_AMDGPU_CIK 232 + case CHIP_BONAIRE: 233 + case CHIP_KAVERI: 234 + case CHIP_KABINI: 235 + case CHIP_HAWAII: 236 + case CHIP_MULLINS: 237 + return AMDGPU_FW_LOAD_DIRECT; 238 + #endif 239 + case CHIP_TOPAZ: 240 + case CHIP_TONGA: 241 + case CHIP_FIJI: 242 + case CHIP_CARRIZO: 243 + case CHIP_STONEY: 244 + case CHIP_POLARIS10: 245 + case CHIP_POLARIS11: 246 + case CHIP_POLARIS12: 247 + if (!load_type) 248 + return AMDGPU_FW_LOAD_DIRECT; 249 + else 250 + return AMDGPU_FW_LOAD_SMU; 251 + case CHIP_VEGA10: 252 + if (!load_type) 253 + return AMDGPU_FW_LOAD_DIRECT; 254 + else 255 + return AMDGPU_FW_LOAD_PSP; 256 + default: 257 + DRM_ERROR("Unknow firmware load type\n"); 258 + } 259 + 260 + return AMDGPU_FW_LOAD_DIRECT; 261 + } 262 + 220 263 static int amdgpu_ucode_init_single_fw(struct amdgpu_firmware_info *ucode, 221 264 uint64_t mc_addr, void *kptr) 222 265 { ··· 316 273 uint64_t fw_mc_addr; 317 274 void *fw_buf_ptr = NULL; 318 275 uint64_t fw_offset = 0; 319 - int i, err; 276 + int i, err, max; 320 277 struct amdgpu_firmware_info *ucode = NULL; 321 278 const struct common_firmware_header *header = NULL; 322 279 ··· 349 306 350 307 amdgpu_bo_unreserve(*bo); 351 308 352 - for (i = 0; i < AMDGPU_UCODE_ID_MAXIMUM; i++) { 309 + /* 310 + * if SMU loaded firmware, it needn't add SMC, UVD, and VCE 311 + * ucode info here 312 + */ 313 + if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) 314 + max = AMDGPU_UCODE_ID_MAXIMUM - 3; 315 + else 316 + max = AMDGPU_UCODE_ID_MAXIMUM; 317 + 318 + for (i = 0; i < max; i++) { 353 319 ucode = &adev->firmware.ucode[i]; 354 320 if (ucode->fw) { 355 321 header = (const struct common_firmware_header *)ucode->fw->data; ··· 383 331 failed_reserve: 384 332 amdgpu_bo_unref(bo); 385 333 failed: 386 - adev->firmware.smu_load = false; 334 + if (err) 335 + adev->firmware.load_type = AMDGPU_FW_LOAD_DIRECT; 387 336 388 337 return err; 389 338 } ··· 393 340 { 394 341 int i; 395 342 struct amdgpu_firmware_info *ucode = NULL; 343 + int max; 396 344 397 - for (i = 0; i < AMDGPU_UCODE_ID_MAXIMUM; i++) { 345 + if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) 346 + max = AMDGPU_UCODE_ID_MAXIMUM - 3; 347 + else 348 + max = AMDGPU_UCODE_ID_MAXIMUM; 349 + 350 + for (i = 0; i < max; i++) { 398 351 ucode = &adev->firmware.ucode[i]; 399 352 if (ucode->fw) { 400 353 ucode->mc_addr = 0;
+3
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h
··· 176 176 int amdgpu_ucode_init_bo(struct amdgpu_device *adev); 177 177 int amdgpu_ucode_fini_bo(struct amdgpu_device *adev); 178 178 179 + enum amdgpu_firmware_load_type 180 + amdgpu_ucode_get_load_type(struct amdgpu_device *adev, int load_type); 181 + 179 182 #endif
+2
drivers/gpu/drm/amd/amdgpu/cik.c
··· 1785 1785 return -EINVAL; 1786 1786 } 1787 1787 1788 + adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type); 1789 + 1788 1790 amdgpu_get_pcie_info(adev); 1789 1791 1790 1792 return 0;
+3 -3
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
··· 1040 1040 } 1041 1041 } 1042 1042 1043 - if (adev->firmware.smu_load) { 1043 + if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) { 1044 1044 info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_PFP]; 1045 1045 info->ucode_id = AMDGPU_UCODE_ID_CP_PFP; 1046 1046 info->fw = adev->gfx.pfp_fw; ··· 4253 4253 gfx_v8_0_init_pg(adev); 4254 4254 4255 4255 if (!adev->pp_enabled) { 4256 - if (!adev->firmware.smu_load) { 4256 + if (adev->firmware.load_type != AMDGPU_FW_LOAD_SMU) { 4257 4257 /* legacy rlc firmware loading */ 4258 4258 r = gfx_v8_0_rlc_load_microcode(adev); 4259 4259 if (r) ··· 5269 5269 gfx_v8_0_enable_gui_idle_interrupt(adev, false); 5270 5270 5271 5271 if (!adev->pp_enabled) { 5272 - if (!adev->firmware.smu_load) { 5272 + if (adev->firmware.load_type != AMDGPU_FW_LOAD_SMU) { 5273 5273 /* legacy firmware loading */ 5274 5274 r = gfx_v8_0_cp_gfx_load_microcode(adev); 5275 5275 if (r)
+2 -2
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
··· 158 158 if (adev->sdma.instance[i].feature_version >= 20) 159 159 adev->sdma.instance[i].burst_nop = true; 160 160 161 - if (adev->firmware.smu_load) { 161 + if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) { 162 162 info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA0 + i]; 163 163 info->ucode_id = AMDGPU_UCODE_ID_SDMA0 + i; 164 164 info->fw = adev->sdma.instance[i].fw; ··· 562 562 int r; 563 563 564 564 if (!adev->pp_enabled) { 565 - if (!adev->firmware.smu_load) { 565 + if (adev->firmware.load_type != AMDGPU_FW_LOAD_SMU) { 566 566 r = sdma_v2_4_load_microcode(adev); 567 567 if (r) 568 568 return r;
+2 -2
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
··· 310 310 if (adev->sdma.instance[i].feature_version >= 20) 311 311 adev->sdma.instance[i].burst_nop = true; 312 312 313 - if (adev->firmware.smu_load) { 313 + if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) { 314 314 info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA0 + i]; 315 315 info->ucode_id = AMDGPU_UCODE_ID_SDMA0 + i; 316 316 info->fw = adev->sdma.instance[i].fw; ··· 771 771 int r, i; 772 772 773 773 if (!adev->pp_enabled) { 774 - if (!adev->firmware.smu_load) { 774 + if (adev->firmware.load_type != AMDGPU_FW_LOAD_SMU) { 775 775 r = sdma_v3_0_load_microcode(adev); 776 776 if (r) 777 777 return r;
+2 -2
drivers/gpu/drm/amd/amdgpu/vi.c
··· 1117 1117 return -EINVAL; 1118 1118 } 1119 1119 1120 - if (amdgpu_smc_load_fw && smc_enabled) 1121 - adev->firmware.smu_load = true; 1120 + /* vi use smc load by default */ 1121 + adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type); 1122 1122 1123 1123 amdgpu_get_pcie_info(adev); 1124 1124