Skip to content

Commit 2d39c7a

Browse files
superm1alexdeucher
authored andcommitted
drm/amd: Load PSP microcode during early_init
Simplifies the code so that all PSP versions will get the firmware name from `amdgpu_ucode_ip_version_decode` and then use this filename to load microcode as part of the early_init process. Any failures will cause the driver to fail to probe before the firmware framebuffer has been removed. Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Lijo Lazar <lijo.lazar@amd.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 93fec4f commit 2d39c7a

File tree

7 files changed

+69
-184
lines changed

7 files changed

+69
-184
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c

Lines changed: 46 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,44 @@ static void psp_check_pmfw_centralized_cstate_management(struct psp_context *psp
123123
}
124124
}
125125

126+
static int psp_init_sriov_microcode(struct psp_context *psp)
127+
{
128+
struct amdgpu_device *adev = psp->adev;
129+
char ucode_prefix[30];
130+
int ret = 0;
131+
132+
amdgpu_ucode_ip_version_decode(adev, MP0_HWIP, ucode_prefix, sizeof(ucode_prefix));
133+
134+
switch (adev->ip_versions[MP0_HWIP][0]) {
135+
case IP_VERSION(9, 0, 0):
136+
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
137+
ret = psp_init_cap_microcode(psp, ucode_prefix);
138+
break;
139+
case IP_VERSION(11, 0, 9):
140+
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
141+
ret = psp_init_cap_microcode(psp, ucode_prefix);
142+
break;
143+
case IP_VERSION(11, 0, 7):
144+
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
145+
ret = psp_init_cap_microcode(psp, ucode_prefix);
146+
break;
147+
case IP_VERSION(13, 0, 2):
148+
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
149+
ret = psp_init_cap_microcode(psp, ucode_prefix);
150+
ret &= psp_init_ta_microcode(psp, ucode_prefix);
151+
break;
152+
case IP_VERSION(13, 0, 0):
153+
adev->virt.autoload_ucode_id = 0;
154+
break;
155+
case IP_VERSION(13, 0, 10):
156+
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MES1_DATA;
157+
break;
158+
default:
159+
return -EINVAL;
160+
}
161+
return ret;
162+
}
163+
126164
static int psp_early_init(void *handle)
127165
{
128166
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -193,7 +231,10 @@ static int psp_early_init(void *handle)
193231

194232
psp_check_pmfw_centralized_cstate_management(psp);
195233

196-
return 0;
234+
if (amdgpu_sriov_vf(adev))
235+
return psp_init_sriov_microcode(psp);
236+
else
237+
return psp_init_microcode(psp);
197238
}
198239

199240
void psp_ta_free_shared_buf(struct ta_mem_context *mem_ctx)
@@ -351,42 +392,6 @@ static bool psp_get_runtime_db_entry(struct amdgpu_device *adev,
351392
return ret;
352393
}
353394

354-
static int psp_init_sriov_microcode(struct psp_context *psp)
355-
{
356-
struct amdgpu_device *adev = psp->adev;
357-
int ret = 0;
358-
359-
switch (adev->ip_versions[MP0_HWIP][0]) {
360-
case IP_VERSION(9, 0, 0):
361-
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
362-
ret = psp_init_cap_microcode(psp, "vega10");
363-
break;
364-
case IP_VERSION(11, 0, 9):
365-
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
366-
ret = psp_init_cap_microcode(psp, "navi12");
367-
break;
368-
case IP_VERSION(11, 0, 7):
369-
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
370-
ret = psp_init_cap_microcode(psp, "sienna_cichlid");
371-
break;
372-
case IP_VERSION(13, 0, 2):
373-
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
374-
ret = psp_init_cap_microcode(psp, "aldebaran");
375-
ret &= psp_init_ta_microcode(psp, "aldebaran");
376-
break;
377-
case IP_VERSION(13, 0, 0):
378-
adev->virt.autoload_ucode_id = 0;
379-
break;
380-
case IP_VERSION(13, 0, 10):
381-
adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MES1_DATA;
382-
break;
383-
default:
384-
ret = -EINVAL;
385-
break;
386-
}
387-
return ret;
388-
}
389-
390395
static int psp_sw_init(void *handle)
391396
{
392397
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -402,15 +407,6 @@ static int psp_sw_init(void *handle)
402407
ret = -ENOMEM;
403408
}
404409

405-
if (amdgpu_sriov_vf(adev))
406-
ret = psp_init_sriov_microcode(psp);
407-
else
408-
ret = psp_init_microcode(psp);
409-
if (ret) {
410-
DRM_ERROR("Failed to load psp firmware!\n");
411-
return ret;
412-
}
413-
414410
adev->psp.xgmi_context.supports_extended_data =
415411
!adev->gmc.xgmi.connected_to_cpu &&
416412
adev->ip_versions[MP0_HWIP][0] == IP_VERSION(13, 0, 2);
@@ -2914,19 +2910,13 @@ int psp_ring_cmd_submit(struct psp_context *psp,
29142910
return 0;
29152911
}
29162912

2917-
int psp_init_asd_microcode(struct psp_context *psp,
2918-
const char *chip_name)
2913+
int psp_init_asd_microcode(struct psp_context *psp, const char *chip_name)
29192914
{
29202915
struct amdgpu_device *adev = psp->adev;
29212916
char fw_name[PSP_FW_NAME_LEN];
29222917
const struct psp_firmware_header_v1_0 *asd_hdr;
29232918
int err = 0;
29242919

2925-
if (!chip_name) {
2926-
dev_err(adev->dev, "invalid chip name for asd microcode\n");
2927-
return -EINVAL;
2928-
}
2929-
29302920
snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_asd.bin", chip_name);
29312921
err = request_firmware(&adev->psp.asd_fw, fw_name, adev->dev);
29322922
if (err)
@@ -2950,19 +2940,13 @@ int psp_init_asd_microcode(struct psp_context *psp,
29502940
return err;
29512941
}
29522942

2953-
int psp_init_toc_microcode(struct psp_context *psp,
2954-
const char *chip_name)
2943+
int psp_init_toc_microcode(struct psp_context *psp, const char *chip_name)
29552944
{
29562945
struct amdgpu_device *adev = psp->adev;
29572946
char fw_name[PSP_FW_NAME_LEN];
29582947
const struct psp_firmware_header_v1_0 *toc_hdr;
29592948
int err = 0;
29602949

2961-
if (!chip_name) {
2962-
dev_err(adev->dev, "invalid chip name for toc microcode\n");
2963-
return -EINVAL;
2964-
}
2965-
29662950
snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_toc.bin", chip_name);
29672951
err = request_firmware(&adev->psp.toc_fw, fw_name, adev->dev);
29682952
if (err)
@@ -3113,8 +3097,7 @@ static int psp_init_sos_base_fw(struct amdgpu_device *adev)
31133097
return 0;
31143098
}
31153099

3116-
int psp_init_sos_microcode(struct psp_context *psp,
3117-
const char *chip_name)
3100+
int psp_init_sos_microcode(struct psp_context *psp, const char *chip_name)
31183101
{
31193102
struct amdgpu_device *adev = psp->adev;
31203103
char fw_name[PSP_FW_NAME_LEN];
@@ -3127,11 +3110,6 @@ int psp_init_sos_microcode(struct psp_context *psp,
31273110
uint8_t *ucode_array_start_addr;
31283111
int fw_index = 0;
31293112

3130-
if (!chip_name) {
3131-
dev_err(adev->dev, "invalid chip name for sos microcode\n");
3132-
return -EINVAL;
3133-
}
3134-
31353113
snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sos.bin", chip_name);
31363114
err = request_firmware(&adev->psp.sos_fw, fw_name, adev->dev);
31373115
if (err)
@@ -3398,20 +3376,14 @@ int psp_init_ta_microcode(struct psp_context *psp, const char *chip_name)
33983376
return err;
33993377
}
34003378

3401-
int psp_init_cap_microcode(struct psp_context *psp,
3402-
const char *chip_name)
3379+
int psp_init_cap_microcode(struct psp_context *psp, const char *chip_name)
34033380
{
34043381
struct amdgpu_device *adev = psp->adev;
34053382
char fw_name[PSP_FW_NAME_LEN];
34063383
const struct psp_firmware_header_v1_0 *cap_hdr_v1_0;
34073384
struct amdgpu_firmware_info *info = NULL;
34083385
int err = 0;
34093386

3410-
if (!chip_name) {
3411-
dev_err(adev->dev, "invalid chip name for cap microcode\n");
3412-
return -EINVAL;
3413-
}
3414-
34153387
if (!amdgpu_sriov_vf(adev)) {
34163388
dev_err(adev->dev, "cap microcode should only be loaded under SRIOV\n");
34173389
return -EINVAL;

drivers/gpu/drm/amd/amdgpu/psp_v10_0.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,10 @@ MODULE_FIRMWARE("amdgpu/raven_ta.bin");
4747
static int psp_v10_0_init_microcode(struct psp_context *psp)
4848
{
4949
struct amdgpu_device *adev = psp->adev;
50-
const char *chip_name;
5150
char ucode_prefix[30];
5251
int err = 0;
5352
DRM_DEBUG("\n");
5453

55-
switch (adev->asic_type) {
56-
case CHIP_RAVEN:
57-
if (adev->apu_flags & AMD_APU_IS_RAVEN2)
58-
chip_name = "raven2";
59-
else if (adev->apu_flags & AMD_APU_IS_PICASSO)
60-
chip_name = "picasso";
61-
else
62-
chip_name = "raven";
63-
break;
64-
default: BUG();
65-
}
6654
amdgpu_ucode_ip_version_decode(adev, MP0_HWIP, ucode_prefix, sizeof(ucode_prefix));
6755

6856
err = psp_init_asd_microcode(psp, ucode_prefix);

drivers/gpu/drm/amd/amdgpu/psp_v11_0.c

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -88,55 +88,20 @@ MODULE_FIRMWARE("amdgpu/beige_goby_ta.bin");
8888
static int psp_v11_0_init_microcode(struct psp_context *psp)
8989
{
9090
struct amdgpu_device *adev = psp->adev;
91-
const char *chip_name;
9291
char ucode_prefix[30];
9392
int err = 0;
9493

9594
DRM_DEBUG("\n");
9695

97-
switch (adev->ip_versions[MP0_HWIP][0]) {
98-
case IP_VERSION(11, 0, 2):
99-
chip_name = "vega20";
100-
break;
101-
case IP_VERSION(11, 0, 0):
102-
chip_name = "navi10";
103-
break;
104-
case IP_VERSION(11, 0, 5):
105-
chip_name = "navi14";
106-
break;
107-
case IP_VERSION(11, 0, 9):
108-
chip_name = "navi12";
109-
break;
110-
case IP_VERSION(11, 0, 4):
111-
chip_name = "arcturus";
112-
break;
113-
case IP_VERSION(11, 0, 7):
114-
chip_name = "sienna_cichlid";
115-
break;
116-
case IP_VERSION(11, 0, 11):
117-
chip_name = "navy_flounder";
118-
break;
119-
case IP_VERSION(11, 5, 0):
120-
chip_name = "vangogh";
121-
break;
122-
case IP_VERSION(11, 0, 12):
123-
chip_name = "dimgrey_cavefish";
124-
break;
125-
case IP_VERSION(11, 0, 13):
126-
chip_name = "beige_goby";
127-
break;
128-
default:
129-
BUG();
130-
}
13196
amdgpu_ucode_ip_version_decode(adev, MP0_HWIP, ucode_prefix, sizeof(ucode_prefix));
13297

13398
switch (adev->ip_versions[MP0_HWIP][0]) {
13499
case IP_VERSION(11, 0, 2):
135100
case IP_VERSION(11, 0, 4):
136-
err = psp_init_sos_microcode(psp, chip_name);
101+
err = psp_init_sos_microcode(psp, ucode_prefix);
137102
if (err)
138103
return err;
139-
err = psp_init_asd_microcode(psp, chip_name);
104+
err = psp_init_asd_microcode(psp, ucode_prefix);
140105
if (err)
141106
return err;
142107
err = psp_init_ta_microcode(psp, ucode_prefix);
@@ -145,10 +110,10 @@ static int psp_v11_0_init_microcode(struct psp_context *psp)
145110
case IP_VERSION(11, 0, 0):
146111
case IP_VERSION(11, 0, 5):
147112
case IP_VERSION(11, 0, 9):
148-
err = psp_init_sos_microcode(psp, chip_name);
113+
err = psp_init_sos_microcode(psp, ucode_prefix);
149114
if (err)
150115
return err;
151-
err = psp_init_asd_microcode(psp, chip_name);
116+
err = psp_init_asd_microcode(psp, ucode_prefix);
152117
if (err)
153118
return err;
154119
err = psp_init_ta_microcode(psp, ucode_prefix);
@@ -158,16 +123,16 @@ static int psp_v11_0_init_microcode(struct psp_context *psp)
158123
case IP_VERSION(11, 0, 11):
159124
case IP_VERSION(11, 0, 12):
160125
case IP_VERSION(11, 0, 13):
161-
err = psp_init_sos_microcode(psp, chip_name);
126+
err = psp_init_sos_microcode(psp, ucode_prefix);
162127
if (err)
163128
return err;
164-
err = psp_init_ta_microcode(psp, chip_name);
129+
err = psp_init_ta_microcode(psp, ucode_prefix);
165130
break;
166131
case IP_VERSION(11, 5, 0):
167-
err = psp_init_asd_microcode(psp, chip_name);
132+
err = psp_init_asd_microcode(psp, ucode_prefix);
168133
if (err)
169134
return err;
170-
err = psp_init_toc_microcode(psp, chip_name);
135+
err = psp_init_toc_microcode(psp, ucode_prefix);
171136
break;
172137
default:
173138
BUG();

drivers/gpu/drm/amd/amdgpu/psp_v12_0.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,13 @@ MODULE_FIRMWARE("amdgpu/green_sardine_ta.bin");
4848
static int psp_v12_0_init_microcode(struct psp_context *psp)
4949
{
5050
struct amdgpu_device *adev = psp->adev;
51-
const char *chip_name;
5251
char ucode_prefix[30];
5352
int err = 0;
5453
DRM_DEBUG("\n");
5554

56-
switch (adev->asic_type) {
57-
case CHIP_RENOIR:
58-
if (adev->apu_flags & AMD_APU_IS_RENOIR)
59-
chip_name = "renoir";
60-
else
61-
chip_name = "green_sardine";
62-
break;
63-
default:
64-
BUG();
65-
}
6655
amdgpu_ucode_ip_version_decode(adev, MP0_HWIP, ucode_prefix, sizeof(ucode_prefix));
6756

68-
err = psp_init_asd_microcode(psp, chip_name);
57+
err = psp_init_asd_microcode(psp, ucode_prefix);
6958
if (err)
7059
return err;
7160

0 commit comments

Comments
 (0)