1d38ceaf9SAlex Deucher /*
2d38ceaf9SAlex Deucher * Copyright 2014 Advanced Micro Devices, Inc.
3d38ceaf9SAlex Deucher *
4d38ceaf9SAlex Deucher * Permission is hereby granted, free of charge, to any person obtaining a
5d38ceaf9SAlex Deucher * copy of this software and associated documentation files (the "Software"),
6d38ceaf9SAlex Deucher * to deal in the Software without restriction, including without limitation
7d38ceaf9SAlex Deucher * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d38ceaf9SAlex Deucher * and/or sell copies of the Software, and to permit persons to whom the
9d38ceaf9SAlex Deucher * Software is furnished to do so, subject to the following conditions:
10d38ceaf9SAlex Deucher *
11d38ceaf9SAlex Deucher * The above copyright notice and this permission notice shall be included in
12d38ceaf9SAlex Deucher * all copies or substantial portions of the Software.
13d38ceaf9SAlex Deucher *
14d38ceaf9SAlex Deucher * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15d38ceaf9SAlex Deucher * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16d38ceaf9SAlex Deucher * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17d38ceaf9SAlex Deucher * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18d38ceaf9SAlex Deucher * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19d38ceaf9SAlex Deucher * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20d38ceaf9SAlex Deucher * OTHER DEALINGS IN THE SOFTWARE.
21d38ceaf9SAlex Deucher *
22d38ceaf9SAlex Deucher */
23d38ceaf9SAlex Deucher
24d38ceaf9SAlex Deucher #include <linux/firmware.h>
25d38ceaf9SAlex Deucher #include <linux/slab.h>
26d38ceaf9SAlex Deucher #include <linux/module.h>
27fdf2f6c5SSam Ravnborg
28d38ceaf9SAlex Deucher #include "amdgpu.h"
29d38ceaf9SAlex Deucher #include "amdgpu_ucode.h"
30d38ceaf9SAlex Deucher
311bfe5e77SYang Wang #define AMDGPU_UCODE_NAME_MAX (128)
321bfe5e77SYang Wang
amdgpu_ucode_print_common_hdr(const struct common_firmware_header * hdr)33d38ceaf9SAlex Deucher static void amdgpu_ucode_print_common_hdr(const struct common_firmware_header *hdr)
34d38ceaf9SAlex Deucher {
35d38ceaf9SAlex Deucher DRM_DEBUG("size_bytes: %u\n", le32_to_cpu(hdr->size_bytes));
36d38ceaf9SAlex Deucher DRM_DEBUG("header_size_bytes: %u\n", le32_to_cpu(hdr->header_size_bytes));
37d38ceaf9SAlex Deucher DRM_DEBUG("header_version_major: %u\n", le16_to_cpu(hdr->header_version_major));
38d38ceaf9SAlex Deucher DRM_DEBUG("header_version_minor: %u\n", le16_to_cpu(hdr->header_version_minor));
39d38ceaf9SAlex Deucher DRM_DEBUG("ip_version_major: %u\n", le16_to_cpu(hdr->ip_version_major));
40d38ceaf9SAlex Deucher DRM_DEBUG("ip_version_minor: %u\n", le16_to_cpu(hdr->ip_version_minor));
41d38ceaf9SAlex Deucher DRM_DEBUG("ucode_version: 0x%08x\n", le32_to_cpu(hdr->ucode_version));
42d38ceaf9SAlex Deucher DRM_DEBUG("ucode_size_bytes: %u\n", le32_to_cpu(hdr->ucode_size_bytes));
43d38ceaf9SAlex Deucher DRM_DEBUG("ucode_array_offset_bytes: %u\n",
44d38ceaf9SAlex Deucher le32_to_cpu(hdr->ucode_array_offset_bytes));
45d38ceaf9SAlex Deucher DRM_DEBUG("crc32: 0x%08x\n", le32_to_cpu(hdr->crc32));
46d38ceaf9SAlex Deucher }
47d38ceaf9SAlex Deucher
amdgpu_ucode_print_mc_hdr(const struct common_firmware_header * hdr)48d38ceaf9SAlex Deucher void amdgpu_ucode_print_mc_hdr(const struct common_firmware_header *hdr)
49d38ceaf9SAlex Deucher {
50d38ceaf9SAlex Deucher uint16_t version_major = le16_to_cpu(hdr->header_version_major);
51d38ceaf9SAlex Deucher uint16_t version_minor = le16_to_cpu(hdr->header_version_minor);
52d38ceaf9SAlex Deucher
53d38ceaf9SAlex Deucher DRM_DEBUG("MC\n");
54d38ceaf9SAlex Deucher amdgpu_ucode_print_common_hdr(hdr);
55d38ceaf9SAlex Deucher
56d38ceaf9SAlex Deucher if (version_major == 1) {
57d38ceaf9SAlex Deucher const struct mc_firmware_header_v1_0 *mc_hdr =
58d38ceaf9SAlex Deucher container_of(hdr, struct mc_firmware_header_v1_0, header);
59d38ceaf9SAlex Deucher
60d38ceaf9SAlex Deucher DRM_DEBUG("io_debug_size_bytes: %u\n",
61d38ceaf9SAlex Deucher le32_to_cpu(mc_hdr->io_debug_size_bytes));
62d38ceaf9SAlex Deucher DRM_DEBUG("io_debug_array_offset_bytes: %u\n",
63d38ceaf9SAlex Deucher le32_to_cpu(mc_hdr->io_debug_array_offset_bytes));
64d38ceaf9SAlex Deucher } else {
65d38ceaf9SAlex Deucher DRM_ERROR("Unknown MC ucode version: %u.%u\n", version_major, version_minor);
66d38ceaf9SAlex Deucher }
67d38ceaf9SAlex Deucher }
68d38ceaf9SAlex Deucher
amdgpu_ucode_print_smc_hdr(const struct common_firmware_header * hdr)69d38ceaf9SAlex Deucher void amdgpu_ucode_print_smc_hdr(const struct common_firmware_header *hdr)
70d38ceaf9SAlex Deucher {
71d38ceaf9SAlex Deucher uint16_t version_major = le16_to_cpu(hdr->header_version_major);
72d38ceaf9SAlex Deucher uint16_t version_minor = le16_to_cpu(hdr->header_version_minor);
73a6d64c1aSKevin Wang const struct smc_firmware_header_v1_0 *v1_0_hdr;
74a6d64c1aSKevin Wang const struct smc_firmware_header_v2_0 *v2_0_hdr;
75a6d64c1aSKevin Wang const struct smc_firmware_header_v2_1 *v2_1_hdr;
76d38ceaf9SAlex Deucher
77d38ceaf9SAlex Deucher DRM_DEBUG("SMC\n");
78d38ceaf9SAlex Deucher amdgpu_ucode_print_common_hdr(hdr);
79d38ceaf9SAlex Deucher
80d38ceaf9SAlex Deucher if (version_major == 1) {
81a6d64c1aSKevin Wang v1_0_hdr = container_of(hdr, struct smc_firmware_header_v1_0, header);
82a6d64c1aSKevin Wang DRM_DEBUG("ucode_start_addr: %u\n", le32_to_cpu(v1_0_hdr->ucode_start_addr));
83336a1c82SHuang Rui } else if (version_major == 2) {
84a6d64c1aSKevin Wang switch (version_minor) {
85a6d64c1aSKevin Wang case 0:
86a6d64c1aSKevin Wang v2_0_hdr = container_of(hdr, struct smc_firmware_header_v2_0, v1_0.header);
87a6d64c1aSKevin Wang DRM_DEBUG("ppt_offset_bytes: %u\n", le32_to_cpu(v2_0_hdr->ppt_offset_bytes));
88a6d64c1aSKevin Wang DRM_DEBUG("ppt_size_bytes: %u\n", le32_to_cpu(v2_0_hdr->ppt_size_bytes));
89a6d64c1aSKevin Wang break;
90a6d64c1aSKevin Wang case 1:
91a6d64c1aSKevin Wang v2_1_hdr = container_of(hdr, struct smc_firmware_header_v2_1, v1_0.header);
92a6d64c1aSKevin Wang DRM_DEBUG("pptable_count: %u\n", le32_to_cpu(v2_1_hdr->pptable_count));
93a6d64c1aSKevin Wang DRM_DEBUG("pptable_entry_offset: %u\n", le32_to_cpu(v2_1_hdr->pptable_entry_offset));
94a6d64c1aSKevin Wang break;
95a6d64c1aSKevin Wang default:
96a6d64c1aSKevin Wang break;
97a6d64c1aSKevin Wang }
98336a1c82SHuang Rui
99d38ceaf9SAlex Deucher } else {
100d38ceaf9SAlex Deucher DRM_ERROR("Unknown SMC ucode version: %u.%u\n", version_major, version_minor);
101d38ceaf9SAlex Deucher }
102d38ceaf9SAlex Deucher }
103d38ceaf9SAlex Deucher
amdgpu_ucode_print_gfx_hdr(const struct common_firmware_header * hdr)104d38ceaf9SAlex Deucher void amdgpu_ucode_print_gfx_hdr(const struct common_firmware_header *hdr)
105d38ceaf9SAlex Deucher {
106d38ceaf9SAlex Deucher uint16_t version_major = le16_to_cpu(hdr->header_version_major);
107d38ceaf9SAlex Deucher uint16_t version_minor = le16_to_cpu(hdr->header_version_minor);
108d38ceaf9SAlex Deucher
109d38ceaf9SAlex Deucher DRM_DEBUG("GFX\n");
110d38ceaf9SAlex Deucher amdgpu_ucode_print_common_hdr(hdr);
111d38ceaf9SAlex Deucher
112d38ceaf9SAlex Deucher if (version_major == 1) {
113d38ceaf9SAlex Deucher const struct gfx_firmware_header_v1_0 *gfx_hdr =
114d38ceaf9SAlex Deucher container_of(hdr, struct gfx_firmware_header_v1_0, header);
115d38ceaf9SAlex Deucher
116d38ceaf9SAlex Deucher DRM_DEBUG("ucode_feature_version: %u\n",
117d38ceaf9SAlex Deucher le32_to_cpu(gfx_hdr->ucode_feature_version));
118d38ceaf9SAlex Deucher DRM_DEBUG("jt_offset: %u\n", le32_to_cpu(gfx_hdr->jt_offset));
119d38ceaf9SAlex Deucher DRM_DEBUG("jt_size: %u\n", le32_to_cpu(gfx_hdr->jt_size));
120641f053eSLikun Gao } else if (version_major == 2) {
121641f053eSLikun Gao const struct gfx_firmware_header_v2_0 *gfx_hdr =
122641f053eSLikun Gao container_of(hdr, struct gfx_firmware_header_v2_0, header);
123641f053eSLikun Gao
124641f053eSLikun Gao DRM_DEBUG("ucode_feature_version: %u\n",
125641f053eSLikun Gao le32_to_cpu(gfx_hdr->ucode_feature_version));
126d38ceaf9SAlex Deucher } else {
127d38ceaf9SAlex Deucher DRM_ERROR("Unknown GFX ucode version: %u.%u\n", version_major, version_minor);
128d38ceaf9SAlex Deucher }
129d38ceaf9SAlex Deucher }
130d38ceaf9SAlex Deucher
amdgpu_ucode_print_rlc_hdr(const struct common_firmware_header * hdr)131d38ceaf9SAlex Deucher void amdgpu_ucode_print_rlc_hdr(const struct common_firmware_header *hdr)
132d38ceaf9SAlex Deucher {
133d38ceaf9SAlex Deucher uint16_t version_major = le16_to_cpu(hdr->header_version_major);
134d38ceaf9SAlex Deucher uint16_t version_minor = le16_to_cpu(hdr->header_version_minor);
135d38ceaf9SAlex Deucher
136d38ceaf9SAlex Deucher DRM_DEBUG("RLC\n");
137d38ceaf9SAlex Deucher amdgpu_ucode_print_common_hdr(hdr);
138d38ceaf9SAlex Deucher
139d38ceaf9SAlex Deucher if (version_major == 1) {
140d38ceaf9SAlex Deucher const struct rlc_firmware_header_v1_0 *rlc_hdr =
141d38ceaf9SAlex Deucher container_of(hdr, struct rlc_firmware_header_v1_0, header);
142d38ceaf9SAlex Deucher
143d38ceaf9SAlex Deucher DRM_DEBUG("ucode_feature_version: %u\n",
144d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->ucode_feature_version));
145d38ceaf9SAlex Deucher DRM_DEBUG("save_and_restore_offset: %u\n",
146d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->save_and_restore_offset));
147d38ceaf9SAlex Deucher DRM_DEBUG("clear_state_descriptor_offset: %u\n",
148d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->clear_state_descriptor_offset));
149d38ceaf9SAlex Deucher DRM_DEBUG("avail_scratch_ram_locations: %u\n",
150d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->avail_scratch_ram_locations));
151d38ceaf9SAlex Deucher DRM_DEBUG("master_pkt_description_offset: %u\n",
152d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->master_pkt_description_offset));
153d38ceaf9SAlex Deucher } else if (version_major == 2) {
154d38ceaf9SAlex Deucher const struct rlc_firmware_header_v2_0 *rlc_hdr =
155d38ceaf9SAlex Deucher container_of(hdr, struct rlc_firmware_header_v2_0, header);
156d5c6ad72SHawking Zhang const struct rlc_firmware_header_v2_1 *rlc_hdr_v2_1 =
157d5c6ad72SHawking Zhang container_of(rlc_hdr, struct rlc_firmware_header_v2_1, v2_0);
158d5c6ad72SHawking Zhang const struct rlc_firmware_header_v2_2 *rlc_hdr_v2_2 =
159d5c6ad72SHawking Zhang container_of(rlc_hdr_v2_1, struct rlc_firmware_header_v2_2, v2_1);
160d5c6ad72SHawking Zhang const struct rlc_firmware_header_v2_3 *rlc_hdr_v2_3 =
161d5c6ad72SHawking Zhang container_of(rlc_hdr_v2_2, struct rlc_firmware_header_v2_3, v2_2);
162d5c6ad72SHawking Zhang const struct rlc_firmware_header_v2_4 *rlc_hdr_v2_4 =
163d5c6ad72SHawking Zhang container_of(rlc_hdr_v2_3, struct rlc_firmware_header_v2_4, v2_3);
164d38ceaf9SAlex Deucher
165d5c6ad72SHawking Zhang switch (version_minor) {
166d5c6ad72SHawking Zhang case 0:
167d5c6ad72SHawking Zhang /* rlc_hdr v2_0 */
168d38ceaf9SAlex Deucher DRM_DEBUG("ucode_feature_version: %u\n",
169d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->ucode_feature_version));
170d38ceaf9SAlex Deucher DRM_DEBUG("jt_offset: %u\n", le32_to_cpu(rlc_hdr->jt_offset));
171d38ceaf9SAlex Deucher DRM_DEBUG("jt_size: %u\n", le32_to_cpu(rlc_hdr->jt_size));
172d38ceaf9SAlex Deucher DRM_DEBUG("save_and_restore_offset: %u\n",
173d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->save_and_restore_offset));
174d38ceaf9SAlex Deucher DRM_DEBUG("clear_state_descriptor_offset: %u\n",
175d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->clear_state_descriptor_offset));
176d38ceaf9SAlex Deucher DRM_DEBUG("avail_scratch_ram_locations: %u\n",
177d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->avail_scratch_ram_locations));
178d38ceaf9SAlex Deucher DRM_DEBUG("reg_restore_list_size: %u\n",
179d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_restore_list_size));
180d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_format_start: %u\n",
181d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_format_start));
182d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_format_separate_start: %u\n",
183d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_format_separate_start));
184d38ceaf9SAlex Deucher DRM_DEBUG("starting_offsets_start: %u\n",
185d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->starting_offsets_start));
186d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_format_size_bytes: %u\n",
187d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_format_size_bytes));
188d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_format_array_offset_bytes: %u\n",
189d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_format_array_offset_bytes));
190d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_size_bytes: %u\n",
191d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_size_bytes));
192d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_array_offset_bytes: %u\n",
193d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_array_offset_bytes));
194d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_format_separate_size_bytes: %u\n",
195d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_format_separate_size_bytes));
196d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_format_separate_array_offset_bytes: %u\n",
197d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_format_separate_array_offset_bytes));
198d38ceaf9SAlex Deucher DRM_DEBUG("reg_list_separate_size_bytes: %u\n",
199d38ceaf9SAlex Deucher le32_to_cpu(rlc_hdr->reg_list_separate_size_bytes));
200d40e9b13SHuang Rui DRM_DEBUG("reg_list_separate_array_offset_bytes: %u\n",
201d40e9b13SHuang Rui le32_to_cpu(rlc_hdr->reg_list_separate_array_offset_bytes));
202d5c6ad72SHawking Zhang break;
203d5c6ad72SHawking Zhang case 1:
204d5c6ad72SHawking Zhang /* rlc_hdr v2_1 */
205d40e9b13SHuang Rui DRM_DEBUG("reg_list_format_direct_reg_list_length: %u\n",
206d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->reg_list_format_direct_reg_list_length));
207d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_cntl_ucode_ver: %u\n",
208d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_cntl_ucode_ver));
209d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_cntl_feature_ver: %u\n",
210d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_cntl_feature_ver));
211d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_cntl_size_bytes %u\n",
212d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_cntl_size_bytes));
213d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_cntl_offset_bytes: %u\n",
214d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_cntl_offset_bytes));
215d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_gpm_ucode_ver: %u\n",
216d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_gpm_ucode_ver));
217d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_gpm_feature_ver: %u\n",
218d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_gpm_feature_ver));
219d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_gpm_size_bytes %u\n",
220d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_gpm_size_bytes));
221d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_gpm_offset_bytes: %u\n",
222d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_gpm_offset_bytes));
223d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_srm_ucode_ver: %u\n",
224d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_srm_ucode_ver));
225d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_srm_feature_ver: %u\n",
226d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_srm_feature_ver));
227d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_srm_size_bytes %u\n",
228d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_srm_size_bytes));
229d40e9b13SHuang Rui DRM_DEBUG("save_restore_list_srm_offset_bytes: %u\n",
230d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_1->save_restore_list_srm_offset_bytes));
231d5c6ad72SHawking Zhang break;
232d5c6ad72SHawking Zhang case 2:
233d5c6ad72SHawking Zhang /* rlc_hdr v2_2 */
234d5c6ad72SHawking Zhang DRM_DEBUG("rlc_iram_ucode_size_bytes: %u\n",
235d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_2->rlc_iram_ucode_size_bytes));
236d5c6ad72SHawking Zhang DRM_DEBUG("rlc_iram_ucode_offset_bytes: %u\n",
237d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_2->rlc_iram_ucode_offset_bytes));
238d5c6ad72SHawking Zhang DRM_DEBUG("rlc_dram_ucode_size_bytes: %u\n",
239d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_2->rlc_dram_ucode_size_bytes));
240d5c6ad72SHawking Zhang DRM_DEBUG("rlc_dram_ucode_offset_bytes: %u\n",
241d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_2->rlc_dram_ucode_offset_bytes));
242d5c6ad72SHawking Zhang break;
243d5c6ad72SHawking Zhang case 3:
244d5c6ad72SHawking Zhang /* rlc_hdr v2_3 */
245d5c6ad72SHawking Zhang DRM_DEBUG("rlcp_ucode_version: %u\n",
246d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_3->rlcp_ucode_version));
247d5c6ad72SHawking Zhang DRM_DEBUG("rlcp_ucode_feature_version: %u\n",
248d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_3->rlcp_ucode_feature_version));
249d5c6ad72SHawking Zhang DRM_DEBUG("rlcp_ucode_size_bytes: %u\n",
250d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_3->rlcp_ucode_size_bytes));
251d5c6ad72SHawking Zhang DRM_DEBUG("rlcp_ucode_offset_bytes: %u\n",
252d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_3->rlcp_ucode_offset_bytes));
253d5c6ad72SHawking Zhang DRM_DEBUG("rlcv_ucode_version: %u\n",
254d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_3->rlcv_ucode_version));
255d5c6ad72SHawking Zhang DRM_DEBUG("rlcv_ucode_feature_version: %u\n",
256d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_3->rlcv_ucode_feature_version));
257d5c6ad72SHawking Zhang DRM_DEBUG("rlcv_ucode_size_bytes: %u\n",
258d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_3->rlcv_ucode_size_bytes));
259d5c6ad72SHawking Zhang DRM_DEBUG("rlcv_ucode_offset_bytes: %u\n",
260d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_3->rlcv_ucode_offset_bytes));
261d5c6ad72SHawking Zhang break;
262d5c6ad72SHawking Zhang case 4:
263d5c6ad72SHawking Zhang /* rlc_hdr v2_4 */
264d5c6ad72SHawking Zhang DRM_DEBUG("global_tap_delays_ucode_size_bytes :%u\n",
265d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->global_tap_delays_ucode_size_bytes));
266d5c6ad72SHawking Zhang DRM_DEBUG("global_tap_delays_ucode_offset_bytes: %u\n",
267d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->global_tap_delays_ucode_offset_bytes));
268d5c6ad72SHawking Zhang DRM_DEBUG("se0_tap_delays_ucode_size_bytes :%u\n",
269d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->se0_tap_delays_ucode_size_bytes));
270d5c6ad72SHawking Zhang DRM_DEBUG("se0_tap_delays_ucode_offset_bytes: %u\n",
271d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->se0_tap_delays_ucode_offset_bytes));
272d5c6ad72SHawking Zhang DRM_DEBUG("se1_tap_delays_ucode_size_bytes :%u\n",
273d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->se1_tap_delays_ucode_size_bytes));
274d5c6ad72SHawking Zhang DRM_DEBUG("se1_tap_delays_ucode_offset_bytes: %u\n",
275d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->se1_tap_delays_ucode_offset_bytes));
276d5c6ad72SHawking Zhang DRM_DEBUG("se2_tap_delays_ucode_size_bytes :%u\n",
277d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->se2_tap_delays_ucode_size_bytes));
278d5c6ad72SHawking Zhang DRM_DEBUG("se2_tap_delays_ucode_offset_bytes: %u\n",
279d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->se2_tap_delays_ucode_offset_bytes));
280d5c6ad72SHawking Zhang DRM_DEBUG("se3_tap_delays_ucode_size_bytes :%u\n",
281d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->se3_tap_delays_ucode_size_bytes));
282d5c6ad72SHawking Zhang DRM_DEBUG("se3_tap_delays_ucode_offset_bytes: %u\n",
283d5c6ad72SHawking Zhang le32_to_cpu(rlc_hdr_v2_4->se3_tap_delays_ucode_offset_bytes));
284d5c6ad72SHawking Zhang break;
285d5c6ad72SHawking Zhang default:
286d5c6ad72SHawking Zhang DRM_ERROR("Unknown RLC v2 ucode: v2.%u\n", version_minor);
287d5c6ad72SHawking Zhang break;
288d40e9b13SHuang Rui }
289d38ceaf9SAlex Deucher } else {
290d38ceaf9SAlex Deucher DRM_ERROR("Unknown RLC ucode version: %u.%u\n", version_major, version_minor);
291d38ceaf9SAlex Deucher }
292d38ceaf9SAlex Deucher }
293d38ceaf9SAlex Deucher
amdgpu_ucode_print_sdma_hdr(const struct common_firmware_header * hdr)294d38ceaf9SAlex Deucher void amdgpu_ucode_print_sdma_hdr(const struct common_firmware_header *hdr)
295d38ceaf9SAlex Deucher {
296d38ceaf9SAlex Deucher uint16_t version_major = le16_to_cpu(hdr->header_version_major);
297d38ceaf9SAlex Deucher uint16_t version_minor = le16_to_cpu(hdr->header_version_minor);
298d38ceaf9SAlex Deucher
299d38ceaf9SAlex Deucher DRM_DEBUG("SDMA\n");
300d38ceaf9SAlex Deucher amdgpu_ucode_print_common_hdr(hdr);
301d38ceaf9SAlex Deucher
302d38ceaf9SAlex Deucher if (version_major == 1) {
303d38ceaf9SAlex Deucher const struct sdma_firmware_header_v1_0 *sdma_hdr =
304d38ceaf9SAlex Deucher container_of(hdr, struct sdma_firmware_header_v1_0, header);
305d38ceaf9SAlex Deucher
306d38ceaf9SAlex Deucher DRM_DEBUG("ucode_feature_version: %u\n",
307d38ceaf9SAlex Deucher le32_to_cpu(sdma_hdr->ucode_feature_version));
308d38ceaf9SAlex Deucher DRM_DEBUG("ucode_change_version: %u\n",
309d38ceaf9SAlex Deucher le32_to_cpu(sdma_hdr->ucode_change_version));
310d38ceaf9SAlex Deucher DRM_DEBUG("jt_offset: %u\n", le32_to_cpu(sdma_hdr->jt_offset));
311d38ceaf9SAlex Deucher DRM_DEBUG("jt_size: %u\n", le32_to_cpu(sdma_hdr->jt_size));
312d38ceaf9SAlex Deucher if (version_minor >= 1) {
313d38ceaf9SAlex Deucher const struct sdma_firmware_header_v1_1 *sdma_v1_1_hdr =
314d38ceaf9SAlex Deucher container_of(sdma_hdr, struct sdma_firmware_header_v1_1, v1_0);
315d38ceaf9SAlex Deucher DRM_DEBUG("digest_size: %u\n", le32_to_cpu(sdma_v1_1_hdr->digest_size));
316d38ceaf9SAlex Deucher }
3178e070831SLikun Gao } else if (version_major == 2) {
3188e070831SLikun Gao const struct sdma_firmware_header_v2_0 *sdma_hdr =
3198e070831SLikun Gao container_of(hdr, struct sdma_firmware_header_v2_0, header);
3208e070831SLikun Gao
3218e070831SLikun Gao DRM_DEBUG("ucode_feature_version: %u\n",
3228e070831SLikun Gao le32_to_cpu(sdma_hdr->ucode_feature_version));
3238e070831SLikun Gao DRM_DEBUG("ctx_jt_offset: %u\n", le32_to_cpu(sdma_hdr->ctx_jt_offset));
3248e070831SLikun Gao DRM_DEBUG("ctx_jt_size: %u\n", le32_to_cpu(sdma_hdr->ctx_jt_size));
3258e070831SLikun Gao DRM_DEBUG("ctl_ucode_offset: %u\n", le32_to_cpu(sdma_hdr->ctl_ucode_offset));
3268e070831SLikun Gao DRM_DEBUG("ctl_jt_offset: %u\n", le32_to_cpu(sdma_hdr->ctl_jt_offset));
3278e070831SLikun Gao DRM_DEBUG("ctl_jt_size: %u\n", le32_to_cpu(sdma_hdr->ctl_jt_size));
3289989a924SLikun Gao } else if (version_major == 3) {
3299989a924SLikun Gao const struct sdma_firmware_header_v3_0 *sdma_hdr =
3309989a924SLikun Gao container_of(hdr, struct sdma_firmware_header_v3_0, header);
3319989a924SLikun Gao
3329989a924SLikun Gao DRM_DEBUG("ucode_reversion: %u\n",
3339989a924SLikun Gao le32_to_cpu(sdma_hdr->ucode_feature_version));
334d38ceaf9SAlex Deucher } else {
335d38ceaf9SAlex Deucher DRM_ERROR("Unknown SDMA ucode version: %u.%u\n",
336d38ceaf9SAlex Deucher version_major, version_minor);
337d38ceaf9SAlex Deucher }
338d38ceaf9SAlex Deucher }
339d38ceaf9SAlex Deucher
amdgpu_ucode_print_psp_hdr(const struct common_firmware_header * hdr)3406fa40564SHawking Zhang void amdgpu_ucode_print_psp_hdr(const struct common_firmware_header *hdr)
3416fa40564SHawking Zhang {
3426fa40564SHawking Zhang uint16_t version_major = le16_to_cpu(hdr->header_version_major);
3436fa40564SHawking Zhang uint16_t version_minor = le16_to_cpu(hdr->header_version_minor);
3445fea10d5SHawking Zhang uint32_t fw_index;
3455fea10d5SHawking Zhang const struct psp_fw_bin_desc *desc;
3466fa40564SHawking Zhang
3476fa40564SHawking Zhang DRM_DEBUG("PSP\n");
3486fa40564SHawking Zhang amdgpu_ucode_print_common_hdr(hdr);
3496fa40564SHawking Zhang
3506fa40564SHawking Zhang if (version_major == 1) {
3516fa40564SHawking Zhang const struct psp_firmware_header_v1_0 *psp_hdr =
3526fa40564SHawking Zhang container_of(hdr, struct psp_firmware_header_v1_0, header);
3536fa40564SHawking Zhang
3546fa40564SHawking Zhang DRM_DEBUG("ucode_feature_version: %u\n",
35579a0f441SJohn Clements le32_to_cpu(psp_hdr->sos.fw_version));
3566fa40564SHawking Zhang DRM_DEBUG("sos_offset_bytes: %u\n",
35779a0f441SJohn Clements le32_to_cpu(psp_hdr->sos.offset_bytes));
3586fa40564SHawking Zhang DRM_DEBUG("sos_size_bytes: %u\n",
35979a0f441SJohn Clements le32_to_cpu(psp_hdr->sos.size_bytes));
360434dbb2aSHawking Zhang if (version_minor == 1) {
361434dbb2aSHawking Zhang const struct psp_firmware_header_v1_1 *psp_hdr_v1_1 =
362434dbb2aSHawking Zhang container_of(psp_hdr, struct psp_firmware_header_v1_1, v1_0);
363434dbb2aSHawking Zhang DRM_DEBUG("toc_header_version: %u\n",
36479a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_1->toc.fw_version));
365434dbb2aSHawking Zhang DRM_DEBUG("toc_offset_bytes: %u\n",
36679a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_1->toc.offset_bytes));
367434dbb2aSHawking Zhang DRM_DEBUG("toc_size_bytes: %u\n",
36879a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_1->toc.size_bytes));
36942989359SHawking Zhang DRM_DEBUG("kdb_header_version: %u\n",
37079a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_1->kdb.fw_version));
37142989359SHawking Zhang DRM_DEBUG("kdb_offset_bytes: %u\n",
37279a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_1->kdb.offset_bytes));
37342989359SHawking Zhang DRM_DEBUG("kdb_size_bytes: %u\n",
37479a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_1->kdb.size_bytes));
375434dbb2aSHawking Zhang }
376dc0d9622SJohn Clements if (version_minor == 2) {
377dc0d9622SJohn Clements const struct psp_firmware_header_v1_2 *psp_hdr_v1_2 =
378dc0d9622SJohn Clements container_of(psp_hdr, struct psp_firmware_header_v1_2, v1_0);
379dc0d9622SJohn Clements DRM_DEBUG("kdb_header_version: %u\n",
38079a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_2->kdb.fw_version));
381dc0d9622SJohn Clements DRM_DEBUG("kdb_offset_bytes: %u\n",
38279a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_2->kdb.offset_bytes));
383dc0d9622SJohn Clements DRM_DEBUG("kdb_size_bytes: %u\n",
38479a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_2->kdb.size_bytes));
385dc0d9622SJohn Clements }
38643a188e0SLikun Gao if (version_minor == 3) {
38743a188e0SLikun Gao const struct psp_firmware_header_v1_1 *psp_hdr_v1_1 =
38843a188e0SLikun Gao container_of(psp_hdr, struct psp_firmware_header_v1_1, v1_0);
38943a188e0SLikun Gao const struct psp_firmware_header_v1_3 *psp_hdr_v1_3 =
39043a188e0SLikun Gao container_of(psp_hdr_v1_1, struct psp_firmware_header_v1_3, v1_1);
39143a188e0SLikun Gao DRM_DEBUG("toc_header_version: %u\n",
39279a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->v1_1.toc.fw_version));
39343a188e0SLikun Gao DRM_DEBUG("toc_offset_bytes: %u\n",
39479a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->v1_1.toc.offset_bytes));
39543a188e0SLikun Gao DRM_DEBUG("toc_size_bytes: %u\n",
39679a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->v1_1.toc.size_bytes));
39743a188e0SLikun Gao DRM_DEBUG("kdb_header_version: %u\n",
39879a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->v1_1.kdb.fw_version));
39943a188e0SLikun Gao DRM_DEBUG("kdb_offset_bytes: %u\n",
40079a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->v1_1.kdb.offset_bytes));
40143a188e0SLikun Gao DRM_DEBUG("kdb_size_bytes: %u\n",
40279a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->v1_1.kdb.size_bytes));
40343a188e0SLikun Gao DRM_DEBUG("spl_header_version: %u\n",
40479a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->spl.fw_version));
40543a188e0SLikun Gao DRM_DEBUG("spl_offset_bytes: %u\n",
40679a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->spl.offset_bytes));
40743a188e0SLikun Gao DRM_DEBUG("spl_size_bytes: %u\n",
40879a0f441SJohn Clements le32_to_cpu(psp_hdr_v1_3->spl.size_bytes));
40943a188e0SLikun Gao }
4105fea10d5SHawking Zhang } else if (version_major == 2) {
4115fea10d5SHawking Zhang const struct psp_firmware_header_v2_0 *psp_hdr_v2_0 =
4125fea10d5SHawking Zhang container_of(hdr, struct psp_firmware_header_v2_0, header);
4135fea10d5SHawking Zhang for (fw_index = 0; fw_index < le32_to_cpu(psp_hdr_v2_0->psp_fw_bin_count); fw_index++) {
4145fea10d5SHawking Zhang desc = &(psp_hdr_v2_0->psp_fw_bin[fw_index]);
4155fea10d5SHawking Zhang switch (desc->fw_type) {
4165fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_SOS:
4175fea10d5SHawking Zhang DRM_DEBUG("psp_sos_version: %u\n",
4185fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4195fea10d5SHawking Zhang DRM_DEBUG("psp_sos_size_bytes: %u\n",
4205fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4215fea10d5SHawking Zhang break;
4225fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_SYS_DRV:
4235fea10d5SHawking Zhang DRM_DEBUG("psp_sys_drv_version: %u\n",
4245fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4255fea10d5SHawking Zhang DRM_DEBUG("psp_sys_drv_size_bytes: %u\n",
4265fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4275fea10d5SHawking Zhang break;
4285fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_KDB:
4295fea10d5SHawking Zhang DRM_DEBUG("psp_kdb_version: %u\n",
4305fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4315fea10d5SHawking Zhang DRM_DEBUG("psp_kdb_size_bytes: %u\n",
4325fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4335fea10d5SHawking Zhang break;
4345fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_TOC:
4355fea10d5SHawking Zhang DRM_DEBUG("psp_toc_version: %u\n",
4365fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4375fea10d5SHawking Zhang DRM_DEBUG("psp_toc_size_bytes: %u\n",
4385fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4395fea10d5SHawking Zhang break;
4405fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_SPL:
4415fea10d5SHawking Zhang DRM_DEBUG("psp_spl_version: %u\n",
4425fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4435fea10d5SHawking Zhang DRM_DEBUG("psp_spl_size_bytes: %u\n",
4445fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4455fea10d5SHawking Zhang break;
4465fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_RL:
4475fea10d5SHawking Zhang DRM_DEBUG("psp_rl_version: %u\n",
4485fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4495fea10d5SHawking Zhang DRM_DEBUG("psp_rl_size_bytes: %u\n",
4505fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4515fea10d5SHawking Zhang break;
4525fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_SOC_DRV:
4535fea10d5SHawking Zhang DRM_DEBUG("psp_soc_drv_version: %u\n",
4545fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4555fea10d5SHawking Zhang DRM_DEBUG("psp_soc_drv_size_bytes: %u\n",
4565fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4575fea10d5SHawking Zhang break;
4585fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_INTF_DRV:
4595fea10d5SHawking Zhang DRM_DEBUG("psp_intf_drv_version: %u\n",
4605fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4615fea10d5SHawking Zhang DRM_DEBUG("psp_intf_drv_size_bytes: %u\n",
4625fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4635fea10d5SHawking Zhang break;
4645fea10d5SHawking Zhang case PSP_FW_TYPE_PSP_DBG_DRV:
4655fea10d5SHawking Zhang DRM_DEBUG("psp_dbg_drv_version: %u\n",
4665fea10d5SHawking Zhang le32_to_cpu(desc->fw_version));
4675fea10d5SHawking Zhang DRM_DEBUG("psp_dbg_drv_size_bytes: %u\n",
4685fea10d5SHawking Zhang le32_to_cpu(desc->size_bytes));
4695fea10d5SHawking Zhang break;
47005947892SStanley.Yang case PSP_FW_TYPE_PSP_RAS_DRV:
47105947892SStanley.Yang DRM_DEBUG("psp_ras_drv_version: %u\n",
47205947892SStanley.Yang le32_to_cpu(desc->fw_version));
47305947892SStanley.Yang DRM_DEBUG("psp_ras_drv_size_bytes: %u\n",
47405947892SStanley.Yang le32_to_cpu(desc->size_bytes));
47505947892SStanley.Yang break;
4765fea10d5SHawking Zhang default:
4775fea10d5SHawking Zhang DRM_DEBUG("Unsupported PSP fw type: %d\n", desc->fw_type);
4785fea10d5SHawking Zhang break;
4795fea10d5SHawking Zhang }
4805fea10d5SHawking Zhang }
4816fa40564SHawking Zhang } else {
4826fa40564SHawking Zhang DRM_ERROR("Unknown PSP ucode version: %u.%u\n",
4836fa40564SHawking Zhang version_major, version_minor);
4846fa40564SHawking Zhang }
4856fa40564SHawking Zhang }
4866fa40564SHawking Zhang
amdgpu_ucode_print_gpu_info_hdr(const struct common_firmware_header * hdr)4878ae1a336SAlex Deucher void amdgpu_ucode_print_gpu_info_hdr(const struct common_firmware_header *hdr)
4888ae1a336SAlex Deucher {
4898ae1a336SAlex Deucher uint16_t version_major = le16_to_cpu(hdr->header_version_major);
4908ae1a336SAlex Deucher uint16_t version_minor = le16_to_cpu(hdr->header_version_minor);
4918ae1a336SAlex Deucher
4928ae1a336SAlex Deucher DRM_DEBUG("GPU_INFO\n");
4938ae1a336SAlex Deucher amdgpu_ucode_print_common_hdr(hdr);
4948ae1a336SAlex Deucher
4958ae1a336SAlex Deucher if (version_major == 1) {
4968ae1a336SAlex Deucher const struct gpu_info_firmware_header_v1_0 *gpu_info_hdr =
4978ae1a336SAlex Deucher container_of(hdr, struct gpu_info_firmware_header_v1_0, header);
4988ae1a336SAlex Deucher
4998ae1a336SAlex Deucher DRM_DEBUG("version_major: %u\n",
5008ae1a336SAlex Deucher le16_to_cpu(gpu_info_hdr->version_major));
5018ae1a336SAlex Deucher DRM_DEBUG("version_minor: %u\n",
5028ae1a336SAlex Deucher le16_to_cpu(gpu_info_hdr->version_minor));
5038ae1a336SAlex Deucher } else {
5048ae1a336SAlex Deucher DRM_ERROR("Unknown gpu_info ucode version: %u.%u\n", version_major, version_minor);
5058ae1a336SAlex Deucher }
5068ae1a336SAlex Deucher }
5078ae1a336SAlex Deucher
amdgpu_ucode_validate(const struct firmware * fw)50803000128SMario Limonciello static int amdgpu_ucode_validate(const struct firmware *fw)
509d38ceaf9SAlex Deucher {
510d38ceaf9SAlex Deucher const struct common_firmware_header *hdr =
511d38ceaf9SAlex Deucher (const struct common_firmware_header *)fw->data;
512d38ceaf9SAlex Deucher
513d38ceaf9SAlex Deucher if (fw->size == le32_to_cpu(hdr->size_bytes))
514d38ceaf9SAlex Deucher return 0;
515d38ceaf9SAlex Deucher
516d38ceaf9SAlex Deucher return -EINVAL;
517d38ceaf9SAlex Deucher }
518d38ceaf9SAlex Deucher
amdgpu_ucode_hdr_version(union amdgpu_firmware_header * hdr,uint16_t hdr_major,uint16_t hdr_minor)519d38ceaf9SAlex Deucher bool amdgpu_ucode_hdr_version(union amdgpu_firmware_header *hdr,
520d38ceaf9SAlex Deucher uint16_t hdr_major, uint16_t hdr_minor)
521d38ceaf9SAlex Deucher {
522d38ceaf9SAlex Deucher if ((hdr->common.header_version_major == hdr_major) &&
523d38ceaf9SAlex Deucher (hdr->common.header_version_minor == hdr_minor))
524d38ceaf9SAlex Deucher return true;
5257edda674SLikun Gao return false;
526d38ceaf9SAlex Deucher }
527d38ceaf9SAlex Deucher
528e635ee07SHuang Rui enum amdgpu_firmware_load_type
amdgpu_ucode_get_load_type(struct amdgpu_device * adev,int load_type)529e635ee07SHuang Rui amdgpu_ucode_get_load_type(struct amdgpu_device *adev, int load_type)
530e635ee07SHuang Rui {
531e635ee07SHuang Rui switch (adev->asic_type) {
532e635ee07SHuang Rui #ifdef CONFIG_DRM_AMDGPU_SI
533e635ee07SHuang Rui case CHIP_TAHITI:
534e635ee07SHuang Rui case CHIP_PITCAIRN:
535e635ee07SHuang Rui case CHIP_VERDE:
536e635ee07SHuang Rui case CHIP_OLAND:
537d9997b64SAlex Deucher case CHIP_HAINAN:
538e635ee07SHuang Rui return AMDGPU_FW_LOAD_DIRECT;
539e635ee07SHuang Rui #endif
540e635ee07SHuang Rui #ifdef CONFIG_DRM_AMDGPU_CIK
541e635ee07SHuang Rui case CHIP_BONAIRE:
542e635ee07SHuang Rui case CHIP_KAVERI:
543e635ee07SHuang Rui case CHIP_KABINI:
544e635ee07SHuang Rui case CHIP_HAWAII:
545e635ee07SHuang Rui case CHIP_MULLINS:
546e635ee07SHuang Rui return AMDGPU_FW_LOAD_DIRECT;
547e635ee07SHuang Rui #endif
548e635ee07SHuang Rui case CHIP_TOPAZ:
549e635ee07SHuang Rui case CHIP_TONGA:
550e635ee07SHuang Rui case CHIP_FIJI:
551e635ee07SHuang Rui case CHIP_CARRIZO:
552e635ee07SHuang Rui case CHIP_STONEY:
553e635ee07SHuang Rui case CHIP_POLARIS10:
554e635ee07SHuang Rui case CHIP_POLARIS11:
555e635ee07SHuang Rui case CHIP_POLARIS12:
55634fd54bcSLeo Liu case CHIP_VEGAM:
557e635ee07SHuang Rui return AMDGPU_FW_LOAD_SMU;
558d594e3ccSTao Zhou case CHIP_CYAN_SKILLFISH:
559b8e42844SHuang Rui if (!(load_type &&
560b8e42844SHuang Rui adev->apu_flags & AMD_APU_IS_CYAN_SKILLFISH2))
561d594e3ccSTao Zhou return AMDGPU_FW_LOAD_DIRECT;
562b8e42844SHuang Rui else
563b8e42844SHuang Rui return AMDGPU_FW_LOAD_PSP;
564e635ee07SHuang Rui default:
565aa9f8cc3SAlex Deucher if (!load_type)
566e635ee07SHuang Rui return AMDGPU_FW_LOAD_DIRECT;
567b35c3feaSLikun Gao else if (load_type == 3)
568b35c3feaSLikun Gao return AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO;
569aa9f8cc3SAlex Deucher else
570aa9f8cc3SAlex Deucher return AMDGPU_FW_LOAD_PSP;
571aa9f8cc3SAlex Deucher }
572e635ee07SHuang Rui }
573e635ee07SHuang Rui
amdgpu_ucode_name(enum AMDGPU_UCODE_ID ucode_id)574aae435c6SLang Yu const char *amdgpu_ucode_name(enum AMDGPU_UCODE_ID ucode_id)
575aae435c6SLang Yu {
576aae435c6SLang Yu switch (ucode_id) {
577aae435c6SLang Yu case AMDGPU_UCODE_ID_SDMA0:
578aae435c6SLang Yu return "SDMA0";
579aae435c6SLang Yu case AMDGPU_UCODE_ID_SDMA1:
580aae435c6SLang Yu return "SDMA1";
581aae435c6SLang Yu case AMDGPU_UCODE_ID_SDMA2:
582aae435c6SLang Yu return "SDMA2";
583aae435c6SLang Yu case AMDGPU_UCODE_ID_SDMA3:
584aae435c6SLang Yu return "SDMA3";
585aae435c6SLang Yu case AMDGPU_UCODE_ID_SDMA4:
586aae435c6SLang Yu return "SDMA4";
587aae435c6SLang Yu case AMDGPU_UCODE_ID_SDMA5:
588aae435c6SLang Yu return "SDMA5";
589aae435c6SLang Yu case AMDGPU_UCODE_ID_SDMA6:
590aae435c6SLang Yu return "SDMA6";
591aae435c6SLang Yu case AMDGPU_UCODE_ID_SDMA7:
592aae435c6SLang Yu return "SDMA7";
593619c94c3SLikun Gao case AMDGPU_UCODE_ID_SDMA_UCODE_TH0:
594619c94c3SLikun Gao return "SDMA_CTX";
595619c94c3SLikun Gao case AMDGPU_UCODE_ID_SDMA_UCODE_TH1:
596619c94c3SLikun Gao return "SDMA_CTL";
597aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_CE:
598aae435c6SLang Yu return "CP_CE";
599aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_PFP:
600aae435c6SLang Yu return "CP_PFP";
601aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_ME:
602aae435c6SLang Yu return "CP_ME";
603aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_MEC1:
604aae435c6SLang Yu return "CP_MEC1";
605aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_MEC1_JT:
606aae435c6SLang Yu return "CP_MEC1_JT";
607aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_MEC2:
608aae435c6SLang Yu return "CP_MEC2";
609aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_MEC2_JT:
610aae435c6SLang Yu return "CP_MEC2_JT";
611aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_MES:
612aae435c6SLang Yu return "CP_MES";
613aae435c6SLang Yu case AMDGPU_UCODE_ID_CP_MES_DATA:
614aae435c6SLang Yu return "CP_MES_DATA";
615619c94c3SLikun Gao case AMDGPU_UCODE_ID_CP_MES1:
616619c94c3SLikun Gao return "CP_MES_KIQ";
617619c94c3SLikun Gao case AMDGPU_UCODE_ID_CP_MES1_DATA:
618619c94c3SLikun Gao return "CP_MES_KIQ_DATA";
619aae435c6SLang Yu case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL:
620aae435c6SLang Yu return "RLC_RESTORE_LIST_CNTL";
621aae435c6SLang Yu case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM:
622aae435c6SLang Yu return "RLC_RESTORE_LIST_GPM_MEM";
623aae435c6SLang Yu case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM:
624aae435c6SLang Yu return "RLC_RESTORE_LIST_SRM_MEM";
625aae435c6SLang Yu case AMDGPU_UCODE_ID_RLC_IRAM:
626aae435c6SLang Yu return "RLC_IRAM";
627aae435c6SLang Yu case AMDGPU_UCODE_ID_RLC_DRAM:
628aae435c6SLang Yu return "RLC_DRAM";
629aae435c6SLang Yu case AMDGPU_UCODE_ID_RLC_G:
630aae435c6SLang Yu return "RLC_G";
631619c94c3SLikun Gao case AMDGPU_UCODE_ID_RLC_P:
632619c94c3SLikun Gao return "RLC_P";
633619c94c3SLikun Gao case AMDGPU_UCODE_ID_RLC_V:
634619c94c3SLikun Gao return "RLC_V";
6352207efddSChengming Gui case AMDGPU_UCODE_ID_GLOBAL_TAP_DELAYS:
6362207efddSChengming Gui return "GLOBAL_TAP_DELAYS";
6372207efddSChengming Gui case AMDGPU_UCODE_ID_SE0_TAP_DELAYS:
6382207efddSChengming Gui return "SE0_TAP_DELAYS";
6392207efddSChengming Gui case AMDGPU_UCODE_ID_SE1_TAP_DELAYS:
6402207efddSChengming Gui return "SE1_TAP_DELAYS";
6412207efddSChengming Gui case AMDGPU_UCODE_ID_SE2_TAP_DELAYS:
6422207efddSChengming Gui return "SE2_TAP_DELAYS";
6432207efddSChengming Gui case AMDGPU_UCODE_ID_SE3_TAP_DELAYS:
6442207efddSChengming Gui return "SE3_TAP_DELAYS";
645619c94c3SLikun Gao case AMDGPU_UCODE_ID_IMU_I:
646619c94c3SLikun Gao return "IMU_I";
647619c94c3SLikun Gao case AMDGPU_UCODE_ID_IMU_D:
648619c94c3SLikun Gao return "IMU_D";
649aae435c6SLang Yu case AMDGPU_UCODE_ID_STORAGE:
650aae435c6SLang Yu return "STORAGE";
651aae435c6SLang Yu case AMDGPU_UCODE_ID_SMC:
652aae435c6SLang Yu return "SMC";
653b37c41f2SEvan Quan case AMDGPU_UCODE_ID_PPTABLE:
654b37c41f2SEvan Quan return "PPTABLE";
65579daf692SLijo Lazar case AMDGPU_UCODE_ID_P2S_TABLE:
65679daf692SLijo Lazar return "P2STABLE";
657aae435c6SLang Yu case AMDGPU_UCODE_ID_UVD:
658aae435c6SLang Yu return "UVD";
659aae435c6SLang Yu case AMDGPU_UCODE_ID_UVD1:
660aae435c6SLang Yu return "UVD1";
661aae435c6SLang Yu case AMDGPU_UCODE_ID_VCE:
662aae435c6SLang Yu return "VCE";
663aae435c6SLang Yu case AMDGPU_UCODE_ID_VCN:
664aae435c6SLang Yu return "VCN";
665aae435c6SLang Yu case AMDGPU_UCODE_ID_VCN1:
666aae435c6SLang Yu return "VCN1";
667aae435c6SLang Yu case AMDGPU_UCODE_ID_DMCU_ERAM:
668aae435c6SLang Yu return "DMCU_ERAM";
669aae435c6SLang Yu case AMDGPU_UCODE_ID_DMCU_INTV:
670aae435c6SLang Yu return "DMCU_INTV";
671aae435c6SLang Yu case AMDGPU_UCODE_ID_VCN0_RAM:
672aae435c6SLang Yu return "VCN0_RAM";
673aae435c6SLang Yu case AMDGPU_UCODE_ID_VCN1_RAM:
674aae435c6SLang Yu return "VCN1_RAM";
675aae435c6SLang Yu case AMDGPU_UCODE_ID_DMCUB:
676aae435c6SLang Yu return "DMCUB";
6773cd658deSBill Liu case AMDGPU_UCODE_ID_CAP:
6783cd658deSBill Liu return "CAP";
6794f949033SLang Yu case AMDGPU_UCODE_ID_VPE_CTX:
6804f949033SLang Yu return "VPE_CTX";
6814f949033SLang Yu case AMDGPU_UCODE_ID_VPE_CTL:
6824f949033SLang Yu return "VPE_CTL";
6834f949033SLang Yu case AMDGPU_UCODE_ID_VPE:
6844f949033SLang Yu return "VPE";
6854f949033SLang Yu case AMDGPU_UCODE_ID_UMSCH_MM_UCODE:
6864f949033SLang Yu return "UMSCH_MM_UCODE";
6874f949033SLang Yu case AMDGPU_UCODE_ID_UMSCH_MM_DATA:
6884f949033SLang Yu return "UMSCH_MM_DATA";
689ef2354c7SLang Yu case AMDGPU_UCODE_ID_UMSCH_MM_CMD_BUFFER:
690ef2354c7SLang Yu return "UMSCH_MM_CMD_BUFFER";
691617efef4SSaleemkhan Jamadar case AMDGPU_UCODE_ID_JPEG_RAM:
692617efef4SSaleemkhan Jamadar return "JPEG";
6934badb999SLikun Gao case AMDGPU_UCODE_ID_SDMA_RS64:
6944badb999SLikun Gao return "RS64_SDMA";
6954badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_PFP:
6964badb999SLikun Gao return "RS64_PFP";
6974badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_ME:
6984badb999SLikun Gao return "RS64_ME";
6994badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC:
7004badb999SLikun Gao return "RS64_MEC";
7014badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_PFP_P0_STACK:
7024badb999SLikun Gao return "RS64_PFP_P0_STACK";
7034badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_PFP_P1_STACK:
7044badb999SLikun Gao return "RS64_PFP_P1_STACK";
7054badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_ME_P0_STACK:
7064badb999SLikun Gao return "RS64_ME_P0_STACK";
7074badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_ME_P1_STACK:
7084badb999SLikun Gao return "RS64_ME_P1_STACK";
7094badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC_P0_STACK:
7104badb999SLikun Gao return "RS64_MEC_P0_STACK";
7114badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC_P1_STACK:
7124badb999SLikun Gao return "RS64_MEC_P1_STACK";
7134badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC_P2_STACK:
7144badb999SLikun Gao return "RS64_MEC_P2_STACK";
7154badb999SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC_P3_STACK:
7164badb999SLikun Gao return "RS64_MEC_P3_STACK";
7178fcbfd53SPratap Nirujogi case AMDGPU_UCODE_ID_ISP:
7188fcbfd53SPratap Nirujogi return "ISP";
719aae435c6SLang Yu default:
720aae435c6SLang Yu return "UNKNOWN UCODE";
721aae435c6SLang Yu }
722aae435c6SLang Yu }
723aae435c6SLang Yu
amdgpu_ucode_is_valid(uint32_t fw_version)724b93fb0feSLijo Lazar static inline int amdgpu_ucode_is_valid(uint32_t fw_version)
725b93fb0feSLijo Lazar {
726b93fb0feSLijo Lazar if (!fw_version)
727b93fb0feSLijo Lazar return -EINVAL;
728b93fb0feSLijo Lazar
729b93fb0feSLijo Lazar return 0;
730b93fb0feSLijo Lazar }
731b93fb0feSLijo Lazar
7325bb23532SOri Messinger #define FW_VERSION_ATTR(name, mode, field) \
7335bb23532SOri Messinger static ssize_t show_##name(struct device *dev, \
734b93fb0feSLijo Lazar struct device_attribute *attr, char *buf) \
7355bb23532SOri Messinger { \
7365bb23532SOri Messinger struct drm_device *ddev = dev_get_drvdata(dev); \
7371348969aSLuben Tuikov struct amdgpu_device *adev = drm_to_adev(ddev); \
7385bb23532SOri Messinger \
739b93fb0feSLijo Lazar if (!buf) \
740b93fb0feSLijo Lazar return amdgpu_ucode_is_valid(adev->field); \
741b93fb0feSLijo Lazar \
74240320159SQing Wang return sysfs_emit(buf, "0x%08x\n", adev->field); \
7435bb23532SOri Messinger } \
7445bb23532SOri Messinger static DEVICE_ATTR(name, mode, show_##name, NULL)
7455bb23532SOri Messinger
7465bb23532SOri Messinger FW_VERSION_ATTR(vce_fw_version, 0444, vce.fw_version);
7475bb23532SOri Messinger FW_VERSION_ATTR(uvd_fw_version, 0444, uvd.fw_version);
7485bb23532SOri Messinger FW_VERSION_ATTR(mc_fw_version, 0444, gmc.fw_version);
7495bb23532SOri Messinger FW_VERSION_ATTR(me_fw_version, 0444, gfx.me_fw_version);
7505bb23532SOri Messinger FW_VERSION_ATTR(pfp_fw_version, 0444, gfx.pfp_fw_version);
7515bb23532SOri Messinger FW_VERSION_ATTR(ce_fw_version, 0444, gfx.ce_fw_version);
7525bb23532SOri Messinger FW_VERSION_ATTR(rlc_fw_version, 0444, gfx.rlc_fw_version);
7535bb23532SOri Messinger FW_VERSION_ATTR(rlc_srlc_fw_version, 0444, gfx.rlc_srlc_fw_version);
7545bb23532SOri Messinger FW_VERSION_ATTR(rlc_srlg_fw_version, 0444, gfx.rlc_srlg_fw_version);
7555bb23532SOri Messinger FW_VERSION_ATTR(rlc_srls_fw_version, 0444, gfx.rlc_srls_fw_version);
7565bb23532SOri Messinger FW_VERSION_ATTR(mec_fw_version, 0444, gfx.mec_fw_version);
7575bb23532SOri Messinger FW_VERSION_ATTR(mec2_fw_version, 0444, gfx.mec2_fw_version);
758b7236296SDavid Francis FW_VERSION_ATTR(imu_fw_version, 0444, gfx.imu_fw_version);
759222e0a71SCandice Li FW_VERSION_ATTR(sos_fw_version, 0444, psp.sos.fw_version);
760de3a1e33SCandice Li FW_VERSION_ATTR(asd_fw_version, 0444, psp.asd_context.bin_desc.fw_version);
7614320e6f8SCandice Li FW_VERSION_ATTR(ta_ras_fw_version, 0444, psp.ras_context.context.bin_desc.fw_version);
7624320e6f8SCandice Li FW_VERSION_ATTR(ta_xgmi_fw_version, 0444, psp.xgmi_context.context.bin_desc.fw_version);
7635bb23532SOri Messinger FW_VERSION_ATTR(smc_fw_version, 0444, pm.fw_version);
7645bb23532SOri Messinger FW_VERSION_ATTR(sdma_fw_version, 0444, sdma.instance[0].fw_version);
7655bb23532SOri Messinger FW_VERSION_ATTR(sdma2_fw_version, 0444, sdma.instance[1].fw_version);
7665bb23532SOri Messinger FW_VERSION_ATTR(vcn_fw_version, 0444, vcn.fw_version);
7675bb23532SOri Messinger FW_VERSION_ATTR(dmcu_fw_version, 0444, dm.dmcu_fw_version);
768557d466bSOri Messinger FW_VERSION_ATTR(mes_fw_version, 0444, mes.sched_version & AMDGPU_MES_VERSION_MASK);
769557d466bSOri Messinger FW_VERSION_ATTR(mes_kiq_fw_version, 0444, mes.kiq_version & AMDGPU_MES_VERSION_MASK);
7705bb23532SOri Messinger
7715bb23532SOri Messinger static struct attribute *fw_attrs[] = {
7725bb23532SOri Messinger &dev_attr_vce_fw_version.attr, &dev_attr_uvd_fw_version.attr,
7735bb23532SOri Messinger &dev_attr_mc_fw_version.attr, &dev_attr_me_fw_version.attr,
7745bb23532SOri Messinger &dev_attr_pfp_fw_version.attr, &dev_attr_ce_fw_version.attr,
7755bb23532SOri Messinger &dev_attr_rlc_fw_version.attr, &dev_attr_rlc_srlc_fw_version.attr,
7765bb23532SOri Messinger &dev_attr_rlc_srlg_fw_version.attr, &dev_attr_rlc_srls_fw_version.attr,
7775bb23532SOri Messinger &dev_attr_mec_fw_version.attr, &dev_attr_mec2_fw_version.attr,
7785bb23532SOri Messinger &dev_attr_sos_fw_version.attr, &dev_attr_asd_fw_version.attr,
7795bb23532SOri Messinger &dev_attr_ta_ras_fw_version.attr, &dev_attr_ta_xgmi_fw_version.attr,
7805bb23532SOri Messinger &dev_attr_smc_fw_version.attr, &dev_attr_sdma_fw_version.attr,
7815bb23532SOri Messinger &dev_attr_sdma2_fw_version.attr, &dev_attr_vcn_fw_version.attr,
782b7236296SDavid Francis &dev_attr_dmcu_fw_version.attr, &dev_attr_imu_fw_version.attr,
783557d466bSOri Messinger &dev_attr_mes_fw_version.attr, &dev_attr_mes_kiq_fw_version.attr,
784b7236296SDavid Francis NULL
7855bb23532SOri Messinger };
7865bb23532SOri Messinger
787b93fb0feSLijo Lazar #define to_dev_attr(x) container_of(x, struct device_attribute, attr)
788b93fb0feSLijo Lazar
amdgpu_ucode_sys_visible(struct kobject * kobj,struct attribute * attr,int idx)789b93fb0feSLijo Lazar static umode_t amdgpu_ucode_sys_visible(struct kobject *kobj,
790b93fb0feSLijo Lazar struct attribute *attr, int idx)
791b93fb0feSLijo Lazar {
792b93fb0feSLijo Lazar struct device_attribute *dev_attr = to_dev_attr(attr);
793b93fb0feSLijo Lazar struct device *dev = kobj_to_dev(kobj);
794b93fb0feSLijo Lazar
795b93fb0feSLijo Lazar if (dev_attr->show(dev, dev_attr, NULL) == -EINVAL)
796b93fb0feSLijo Lazar return 0;
797b93fb0feSLijo Lazar
798b93fb0feSLijo Lazar return attr->mode;
799b93fb0feSLijo Lazar }
800b93fb0feSLijo Lazar
8015bb23532SOri Messinger static const struct attribute_group fw_attr_group = {
8025bb23532SOri Messinger .name = "fw_version",
803b93fb0feSLijo Lazar .attrs = fw_attrs,
804b93fb0feSLijo Lazar .is_visible = amdgpu_ucode_sys_visible
8055bb23532SOri Messinger };
8065bb23532SOri Messinger
amdgpu_ucode_sysfs_init(struct amdgpu_device * adev)8075bb23532SOri Messinger int amdgpu_ucode_sysfs_init(struct amdgpu_device *adev)
8085bb23532SOri Messinger {
8095bb23532SOri Messinger return sysfs_create_group(&adev->dev->kobj, &fw_attr_group);
8105bb23532SOri Messinger }
8115bb23532SOri Messinger
amdgpu_ucode_sysfs_fini(struct amdgpu_device * adev)8125bb23532SOri Messinger void amdgpu_ucode_sysfs_fini(struct amdgpu_device *adev)
8135bb23532SOri Messinger {
8145bb23532SOri Messinger sysfs_remove_group(&adev->dev->kobj, &fw_attr_group);
8155bb23532SOri Messinger }
8165bb23532SOri Messinger
amdgpu_ucode_init_single_fw(struct amdgpu_device * adev,struct amdgpu_firmware_info * ucode,uint64_t mc_addr,void * kptr)8172445b227SHuang Rui static int amdgpu_ucode_init_single_fw(struct amdgpu_device *adev,
8182445b227SHuang Rui struct amdgpu_firmware_info *ucode,
819d38ceaf9SAlex Deucher uint64_t mc_addr, void *kptr)
820d38ceaf9SAlex Deucher {
821d38ceaf9SAlex Deucher const struct common_firmware_header *header = NULL;
8222445b227SHuang Rui const struct gfx_firmware_header_v1_0 *cp_hdr = NULL;
82314ab2924SLikun Gao const struct gfx_firmware_header_v2_0 *cpv2_hdr = NULL;
82401fcfc83SDavid Francis const struct dmcu_firmware_header_v1_0 *dmcu_hdr = NULL;
82502350f0bSNicholas Kazlauskas const struct dmcub_firmware_header_v1_0 *dmcub_hdr = NULL;
826aa1faaa1SJack Xiao const struct mes_firmware_header_v1_0 *mes_hdr = NULL;
8276777c8cfSLikun Gao const struct sdma_firmware_header_v2_0 *sdma_hdr = NULL;
828807d90b5SLikun Gao const struct sdma_firmware_header_v3_0 *sdmav3_hdr = NULL;
829a32fa029SLikun Gao const struct imu_firmware_header_v1_0 *imu_hdr = NULL;
830c5d67a0eSLang Yu const struct vpe_firmware_header_v1_0 *vpe_hdr = NULL;
8314f949033SLang Yu const struct umsch_mm_firmware_header_v1_0 *umsch_mm_hdr = NULL;
83202f958a2SLikun Gao u8 *ucode_addr;
833d38ceaf9SAlex Deucher
834e03f04b8SSrinivasan Shanmugam if (!ucode->fw)
835d38ceaf9SAlex Deucher return 0;
836d38ceaf9SAlex Deucher
837d38ceaf9SAlex Deucher ucode->mc_addr = mc_addr;
838d38ceaf9SAlex Deucher ucode->kaddr = kptr;
839d38ceaf9SAlex Deucher
840bed5712eSMonk Liu if (ucode->ucode_id == AMDGPU_UCODE_ID_STORAGE)
841bed5712eSMonk Liu return 0;
842bed5712eSMonk Liu
843d38ceaf9SAlex Deucher header = (const struct common_firmware_header *)ucode->fw->data;
8442445b227SHuang Rui cp_hdr = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
84514ab2924SLikun Gao cpv2_hdr = (const struct gfx_firmware_header_v2_0 *)ucode->fw->data;
84601fcfc83SDavid Francis dmcu_hdr = (const struct dmcu_firmware_header_v1_0 *)ucode->fw->data;
84702350f0bSNicholas Kazlauskas dmcub_hdr = (const struct dmcub_firmware_header_v1_0 *)ucode->fw->data;
848aa1faaa1SJack Xiao mes_hdr = (const struct mes_firmware_header_v1_0 *)ucode->fw->data;
8496777c8cfSLikun Gao sdma_hdr = (const struct sdma_firmware_header_v2_0 *)ucode->fw->data;
850807d90b5SLikun Gao sdmav3_hdr = (const struct sdma_firmware_header_v3_0 *)ucode->fw->data;
851a32fa029SLikun Gao imu_hdr = (const struct imu_firmware_header_v1_0 *)ucode->fw->data;
852c5d67a0eSLang Yu vpe_hdr = (const struct vpe_firmware_header_v1_0 *)ucode->fw->data;
853ef2354c7SLang Yu umsch_mm_hdr = (const struct umsch_mm_firmware_header_v1_0 *)ucode->fw->data;
8542445b227SHuang Rui
85502f958a2SLikun Gao if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
85602f958a2SLikun Gao switch (ucode->ucode_id) {
8576777c8cfSLikun Gao case AMDGPU_UCODE_ID_SDMA_UCODE_TH0:
858aca670e4SLikun Gao ucode->ucode_size = le32_to_cpu(sdma_hdr->ctx_ucode_size_bytes);
8596777c8cfSLikun Gao ucode_addr = (u8 *)ucode->fw->data +
8606777c8cfSLikun Gao le32_to_cpu(sdma_hdr->header.ucode_array_offset_bytes);
8616777c8cfSLikun Gao break;
8626777c8cfSLikun Gao case AMDGPU_UCODE_ID_SDMA_UCODE_TH1:
863aca670e4SLikun Gao ucode->ucode_size = le32_to_cpu(sdma_hdr->ctl_ucode_size_bytes);
8646777c8cfSLikun Gao ucode_addr = (u8 *)ucode->fw->data +
8656777c8cfSLikun Gao le32_to_cpu(sdma_hdr->ctl_ucode_offset);
8666777c8cfSLikun Gao break;
867807d90b5SLikun Gao case AMDGPU_UCODE_ID_SDMA_RS64:
868807d90b5SLikun Gao ucode->ucode_size = le32_to_cpu(sdmav3_hdr->ucode_size_bytes);
869807d90b5SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
870807d90b5SLikun Gao le32_to_cpu(sdmav3_hdr->header.ucode_array_offset_bytes);
871807d90b5SLikun Gao break;
87202f958a2SLikun Gao case AMDGPU_UCODE_ID_CP_MEC1:
87302f958a2SLikun Gao case AMDGPU_UCODE_ID_CP_MEC2:
8742445b227SHuang Rui ucode->ucode_size = le32_to_cpu(header->ucode_size_bytes) -
8752445b227SHuang Rui le32_to_cpu(cp_hdr->jt_size) * 4;
87602f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
87702f958a2SLikun Gao le32_to_cpu(header->ucode_array_offset_bytes);
87802f958a2SLikun Gao break;
87902f958a2SLikun Gao case AMDGPU_UCODE_ID_CP_MEC1_JT:
88002f958a2SLikun Gao case AMDGPU_UCODE_ID_CP_MEC2_JT:
8812445b227SHuang Rui ucode->ucode_size = le32_to_cpu(cp_hdr->jt_size) * 4;
88202f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
8832445b227SHuang Rui le32_to_cpu(header->ucode_array_offset_bytes) +
88402f958a2SLikun Gao le32_to_cpu(cp_hdr->jt_offset) * 4;
88502f958a2SLikun Gao break;
88602f958a2SLikun Gao case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL:
88702f958a2SLikun Gao ucode->ucode_size = adev->gfx.rlc.save_restore_list_cntl_size_bytes;
88802f958a2SLikun Gao ucode_addr = adev->gfx.rlc.save_restore_list_cntl;
88902f958a2SLikun Gao break;
89002f958a2SLikun Gao case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM:
89102f958a2SLikun Gao ucode->ucode_size = adev->gfx.rlc.save_restore_list_gpm_size_bytes;
89202f958a2SLikun Gao ucode_addr = adev->gfx.rlc.save_restore_list_gpm;
89302f958a2SLikun Gao break;
89402f958a2SLikun Gao case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM:
89502f958a2SLikun Gao ucode->ucode_size = adev->gfx.rlc.save_restore_list_srm_size_bytes;
89602f958a2SLikun Gao ucode_addr = adev->gfx.rlc.save_restore_list_srm;
89702f958a2SLikun Gao break;
89802f958a2SLikun Gao case AMDGPU_UCODE_ID_RLC_IRAM:
89902f958a2SLikun Gao ucode->ucode_size = adev->gfx.rlc.rlc_iram_ucode_size_bytes;
90002f958a2SLikun Gao ucode_addr = adev->gfx.rlc.rlc_iram_ucode;
90102f958a2SLikun Gao break;
90202f958a2SLikun Gao case AMDGPU_UCODE_ID_RLC_DRAM:
90302f958a2SLikun Gao ucode->ucode_size = adev->gfx.rlc.rlc_dram_ucode_size_bytes;
90402f958a2SLikun Gao ucode_addr = adev->gfx.rlc.rlc_dram_ucode;
90502f958a2SLikun Gao break;
906a0fe38b4SLikun Gao case AMDGPU_UCODE_ID_RLC_P:
907a0fe38b4SLikun Gao ucode->ucode_size = adev->gfx.rlc.rlcp_ucode_size_bytes;
908a0fe38b4SLikun Gao ucode_addr = adev->gfx.rlc.rlcp_ucode;
909a0fe38b4SLikun Gao break;
9108e41a56aSLikun Gao case AMDGPU_UCODE_ID_RLC_V:
9118e41a56aSLikun Gao ucode->ucode_size = adev->gfx.rlc.rlcv_ucode_size_bytes;
9128e41a56aSLikun Gao ucode_addr = adev->gfx.rlc.rlcv_ucode;
9138e41a56aSLikun Gao break;
9142207efddSChengming Gui case AMDGPU_UCODE_ID_GLOBAL_TAP_DELAYS:
9152207efddSChengming Gui ucode->ucode_size = adev->gfx.rlc.global_tap_delays_ucode_size_bytes;
9162207efddSChengming Gui ucode_addr = adev->gfx.rlc.global_tap_delays_ucode;
9172207efddSChengming Gui break;
9182207efddSChengming Gui case AMDGPU_UCODE_ID_SE0_TAP_DELAYS:
9192207efddSChengming Gui ucode->ucode_size = adev->gfx.rlc.se0_tap_delays_ucode_size_bytes;
9202207efddSChengming Gui ucode_addr = adev->gfx.rlc.se0_tap_delays_ucode;
9212207efddSChengming Gui break;
9222207efddSChengming Gui case AMDGPU_UCODE_ID_SE1_TAP_DELAYS:
9232207efddSChengming Gui ucode->ucode_size = adev->gfx.rlc.se1_tap_delays_ucode_size_bytes;
9242207efddSChengming Gui ucode_addr = adev->gfx.rlc.se1_tap_delays_ucode;
9252207efddSChengming Gui break;
9262207efddSChengming Gui case AMDGPU_UCODE_ID_SE2_TAP_DELAYS:
9272207efddSChengming Gui ucode->ucode_size = adev->gfx.rlc.se2_tap_delays_ucode_size_bytes;
9282207efddSChengming Gui ucode_addr = adev->gfx.rlc.se2_tap_delays_ucode;
9292207efddSChengming Gui break;
9302207efddSChengming Gui case AMDGPU_UCODE_ID_SE3_TAP_DELAYS:
9312207efddSChengming Gui ucode->ucode_size = adev->gfx.rlc.se3_tap_delays_ucode_size_bytes;
9322207efddSChengming Gui ucode_addr = adev->gfx.rlc.se3_tap_delays_ucode;
9332207efddSChengming Gui break;
93402f958a2SLikun Gao case AMDGPU_UCODE_ID_CP_MES:
93502f958a2SLikun Gao ucode->ucode_size = le32_to_cpu(mes_hdr->mes_ucode_size_bytes);
93602f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
93702f958a2SLikun Gao le32_to_cpu(mes_hdr->mes_ucode_offset_bytes);
93802f958a2SLikun Gao break;
93902f958a2SLikun Gao case AMDGPU_UCODE_ID_CP_MES_DATA:
94002f958a2SLikun Gao ucode->ucode_size = le32_to_cpu(mes_hdr->mes_ucode_data_size_bytes);
94102f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
94202f958a2SLikun Gao le32_to_cpu(mes_hdr->mes_ucode_data_offset_bytes);
94302f958a2SLikun Gao break;
944b0f34028SJack Xiao case AMDGPU_UCODE_ID_CP_MES1:
945b0f34028SJack Xiao ucode->ucode_size = le32_to_cpu(mes_hdr->mes_ucode_size_bytes);
946b0f34028SJack Xiao ucode_addr = (u8 *)ucode->fw->data +
947b0f34028SJack Xiao le32_to_cpu(mes_hdr->mes_ucode_offset_bytes);
948b0f34028SJack Xiao break;
949b0f34028SJack Xiao case AMDGPU_UCODE_ID_CP_MES1_DATA:
950b0f34028SJack Xiao ucode->ucode_size = le32_to_cpu(mes_hdr->mes_ucode_data_size_bytes);
951b0f34028SJack Xiao ucode_addr = (u8 *)ucode->fw->data +
952b0f34028SJack Xiao le32_to_cpu(mes_hdr->mes_ucode_data_offset_bytes);
953b0f34028SJack Xiao break;
95402f958a2SLikun Gao case AMDGPU_UCODE_ID_DMCU_ERAM:
95501fcfc83SDavid Francis ucode->ucode_size = le32_to_cpu(header->ucode_size_bytes) -
95601fcfc83SDavid Francis le32_to_cpu(dmcu_hdr->intv_size_bytes);
95702f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
95802f958a2SLikun Gao le32_to_cpu(header->ucode_array_offset_bytes);
95902f958a2SLikun Gao break;
96002f958a2SLikun Gao case AMDGPU_UCODE_ID_DMCU_INTV:
96101fcfc83SDavid Francis ucode->ucode_size = le32_to_cpu(dmcu_hdr->intv_size_bytes);
96202f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
96301fcfc83SDavid Francis le32_to_cpu(header->ucode_array_offset_bytes) +
96402f958a2SLikun Gao le32_to_cpu(dmcu_hdr->intv_offset_bytes);
96502f958a2SLikun Gao break;
96602f958a2SLikun Gao case AMDGPU_UCODE_ID_DMCUB:
96702350f0bSNicholas Kazlauskas ucode->ucode_size = le32_to_cpu(dmcub_hdr->inst_const_bytes);
96802f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
96902f958a2SLikun Gao le32_to_cpu(header->ucode_array_offset_bytes);
97002f958a2SLikun Gao break;
971b37c41f2SEvan Quan case AMDGPU_UCODE_ID_PPTABLE:
972b37c41f2SEvan Quan ucode->ucode_size = ucode->fw->size;
973b37c41f2SEvan Quan ucode_addr = (u8 *)ucode->fw->data;
974b37c41f2SEvan Quan break;
97579daf692SLijo Lazar case AMDGPU_UCODE_ID_P2S_TABLE:
97679daf692SLijo Lazar ucode->ucode_size = ucode->fw->size;
97779daf692SLijo Lazar ucode_addr = (u8 *)ucode->fw->data;
97879daf692SLijo Lazar break;
979a32fa029SLikun Gao case AMDGPU_UCODE_ID_IMU_I:
980a32fa029SLikun Gao ucode->ucode_size = le32_to_cpu(imu_hdr->imu_iram_ucode_size_bytes);
981a32fa029SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
982a32fa029SLikun Gao le32_to_cpu(imu_hdr->header.ucode_array_offset_bytes);
983a32fa029SLikun Gao break;
984a32fa029SLikun Gao case AMDGPU_UCODE_ID_IMU_D:
985a32fa029SLikun Gao ucode->ucode_size = le32_to_cpu(imu_hdr->imu_dram_ucode_size_bytes);
986a32fa029SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
987a32fa029SLikun Gao le32_to_cpu(imu_hdr->header.ucode_array_offset_bytes) +
988a32fa029SLikun Gao le32_to_cpu(imu_hdr->imu_iram_ucode_size_bytes);
989a32fa029SLikun Gao break;
99014ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_PFP:
99114ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->ucode_size_bytes);
99214ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
99314ab2924SLikun Gao le32_to_cpu(header->ucode_array_offset_bytes);
99414ab2924SLikun Gao break;
99514ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_PFP_P0_STACK:
99614ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->data_size_bytes);
99714ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
99814ab2924SLikun Gao le32_to_cpu(cpv2_hdr->data_offset_bytes);
99914ab2924SLikun Gao break;
100014ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_PFP_P1_STACK:
100114ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->data_size_bytes);
100214ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
100314ab2924SLikun Gao le32_to_cpu(cpv2_hdr->data_offset_bytes);
100414ab2924SLikun Gao break;
100514ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_ME:
100614ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->ucode_size_bytes);
100714ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
100814ab2924SLikun Gao le32_to_cpu(header->ucode_array_offset_bytes);
100914ab2924SLikun Gao break;
101014ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_ME_P0_STACK:
101114ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->data_size_bytes);
101214ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
101314ab2924SLikun Gao le32_to_cpu(cpv2_hdr->data_offset_bytes);
101414ab2924SLikun Gao break;
101514ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_ME_P1_STACK:
101614ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->data_size_bytes);
101714ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
101814ab2924SLikun Gao le32_to_cpu(cpv2_hdr->data_offset_bytes);
101914ab2924SLikun Gao break;
102014ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC:
102114ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->ucode_size_bytes);
102214ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
102314ab2924SLikun Gao le32_to_cpu(header->ucode_array_offset_bytes);
102414ab2924SLikun Gao break;
102514ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC_P0_STACK:
102614ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->data_size_bytes);
102714ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
102814ab2924SLikun Gao le32_to_cpu(cpv2_hdr->data_offset_bytes);
102914ab2924SLikun Gao break;
103014ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC_P1_STACK:
103114ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->data_size_bytes);
103214ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
103314ab2924SLikun Gao le32_to_cpu(cpv2_hdr->data_offset_bytes);
103414ab2924SLikun Gao break;
103514ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC_P2_STACK:
103614ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->data_size_bytes);
103714ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
103814ab2924SLikun Gao le32_to_cpu(cpv2_hdr->data_offset_bytes);
103914ab2924SLikun Gao break;
104014ab2924SLikun Gao case AMDGPU_UCODE_ID_CP_RS64_MEC_P3_STACK:
104114ab2924SLikun Gao ucode->ucode_size = le32_to_cpu(cpv2_hdr->data_size_bytes);
104214ab2924SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
104314ab2924SLikun Gao le32_to_cpu(cpv2_hdr->data_offset_bytes);
104414ab2924SLikun Gao break;
1045c5d67a0eSLang Yu case AMDGPU_UCODE_ID_VPE_CTX:
1046c5d67a0eSLang Yu ucode->ucode_size = le32_to_cpu(vpe_hdr->ctx_ucode_size_bytes);
1047c5d67a0eSLang Yu ucode_addr = (u8 *)ucode->fw->data +
1048c5d67a0eSLang Yu le32_to_cpu(vpe_hdr->header.ucode_array_offset_bytes);
1049c5d67a0eSLang Yu break;
1050c5d67a0eSLang Yu case AMDGPU_UCODE_ID_VPE_CTL:
1051c5d67a0eSLang Yu ucode->ucode_size = le32_to_cpu(vpe_hdr->ctl_ucode_size_bytes);
1052c5d67a0eSLang Yu ucode_addr = (u8 *)ucode->fw->data +
1053c5d67a0eSLang Yu le32_to_cpu(vpe_hdr->ctl_ucode_offset);
1054c5d67a0eSLang Yu break;
10554f949033SLang Yu case AMDGPU_UCODE_ID_UMSCH_MM_UCODE:
10564f949033SLang Yu ucode->ucode_size = le32_to_cpu(umsch_mm_hdr->umsch_mm_ucode_size_bytes);
10574f949033SLang Yu ucode_addr = (u8 *)ucode->fw->data +
10584f949033SLang Yu le32_to_cpu(umsch_mm_hdr->header.ucode_array_offset_bytes);
10594f949033SLang Yu break;
10604f949033SLang Yu case AMDGPU_UCODE_ID_UMSCH_MM_DATA:
10614f949033SLang Yu ucode->ucode_size = le32_to_cpu(umsch_mm_hdr->umsch_mm_ucode_data_size_bytes);
10624f949033SLang Yu ucode_addr = (u8 *)ucode->fw->data +
10634f949033SLang Yu le32_to_cpu(umsch_mm_hdr->umsch_mm_ucode_data_offset_bytes);
10644f949033SLang Yu break;
106502f958a2SLikun Gao default:
106602f958a2SLikun Gao ucode->ucode_size = le32_to_cpu(header->ucode_size_bytes);
106702f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
106802f958a2SLikun Gao le32_to_cpu(header->ucode_array_offset_bytes);
106902f958a2SLikun Gao break;
10702445b227SHuang Rui }
107102f958a2SLikun Gao } else {
107202f958a2SLikun Gao ucode->ucode_size = le32_to_cpu(header->ucode_size_bytes);
107302f958a2SLikun Gao ucode_addr = (u8 *)ucode->fw->data +
107402f958a2SLikun Gao le32_to_cpu(header->ucode_array_offset_bytes);
107502f958a2SLikun Gao }
107602f958a2SLikun Gao
107702f958a2SLikun Gao memcpy(ucode->kaddr, ucode_addr, ucode->ucode_size);
1078d38ceaf9SAlex Deucher
1079d38ceaf9SAlex Deucher return 0;
1080d38ceaf9SAlex Deucher }
1081d38ceaf9SAlex Deucher
amdgpu_ucode_patch_jt(struct amdgpu_firmware_info * ucode,uint64_t mc_addr,void * kptr)10824c2b2453SMonk Liu static int amdgpu_ucode_patch_jt(struct amdgpu_firmware_info *ucode,
10834c2b2453SMonk Liu uint64_t mc_addr, void *kptr)
10844c2b2453SMonk Liu {
10854c2b2453SMonk Liu const struct gfx_firmware_header_v1_0 *header = NULL;
10864c2b2453SMonk Liu const struct common_firmware_header *comm_hdr = NULL;
10874c2b2453SMonk Liu uint8_t *src_addr = NULL;
10884c2b2453SMonk Liu uint8_t *dst_addr = NULL;
10894c2b2453SMonk Liu
1090e03f04b8SSrinivasan Shanmugam if (!ucode->fw)
10914c2b2453SMonk Liu return 0;
10924c2b2453SMonk Liu
10934c2b2453SMonk Liu comm_hdr = (const struct common_firmware_header *)ucode->fw->data;
10944c2b2453SMonk Liu header = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
10954c2b2453SMonk Liu dst_addr = ucode->kaddr +
10964c2b2453SMonk Liu ALIGN(le32_to_cpu(comm_hdr->ucode_size_bytes),
10974c2b2453SMonk Liu PAGE_SIZE);
10984c2b2453SMonk Liu src_addr = (uint8_t *)ucode->fw->data +
10994c2b2453SMonk Liu le32_to_cpu(comm_hdr->ucode_array_offset_bytes) +
11004c2b2453SMonk Liu (le32_to_cpu(header->jt_offset) * 4);
11014c2b2453SMonk Liu memcpy(dst_addr, src_addr, le32_to_cpu(header->jt_size) * 4);
11024c2b2453SMonk Liu
11034c2b2453SMonk Liu return 0;
11044c2b2453SMonk Liu }
11054c2b2453SMonk Liu
amdgpu_ucode_create_bo(struct amdgpu_device * adev)1106c8963ea4SRex Zhu int amdgpu_ucode_create_bo(struct amdgpu_device *adev)
1107d38ceaf9SAlex Deucher {
110845b801c2SLikun Gao if ((adev->firmware.load_type != AMDGPU_FW_LOAD_DIRECT) &&
110945b801c2SLikun Gao (adev->firmware.load_type != AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO)) {
1110c8963ea4SRex Zhu amdgpu_bo_create_kernel(adev, adev->firmware.fw_size, PAGE_SIZE,
1111d20e1aecSLe Ma (amdgpu_sriov_vf(adev) || adev->debug_use_vram_fw_buf) ?
1112d20e1aecSLe Ma AMDGPU_GEM_DOMAIN_VRAM : AMDGPU_GEM_DOMAIN_GTT,
1113a95b0275SMonk Liu &adev->firmware.fw_buf,
1114a95b0275SMonk Liu &adev->firmware.fw_buf_mc,
1115a95b0275SMonk Liu &adev->firmware.fw_buf_ptr);
1116c8963ea4SRex Zhu if (!adev->firmware.fw_buf) {
1117a95b0275SMonk Liu dev_err(adev->dev, "failed to create kernel buffer for firmware.fw_buf\n");
1118c8963ea4SRex Zhu return -ENOMEM;
1119c8963ea4SRex Zhu } else if (amdgpu_sriov_vf(adev)) {
1120d59c026bSMonk Liu memset(adev->firmware.fw_buf_ptr, 0, adev->firmware.fw_size);
1121c8963ea4SRex Zhu }
1122c8963ea4SRex Zhu }
1123c8963ea4SRex Zhu return 0;
1124c8963ea4SRex Zhu }
11252445b227SHuang Rui
amdgpu_ucode_free_bo(struct amdgpu_device * adev)1126c8963ea4SRex Zhu void amdgpu_ucode_free_bo(struct amdgpu_device *adev)
1127c8963ea4SRex Zhu {
1128c8963ea4SRex Zhu amdgpu_bo_free_kernel(&adev->firmware.fw_buf,
1129c8963ea4SRex Zhu &adev->firmware.fw_buf_mc,
1130c8963ea4SRex Zhu &adev->firmware.fw_buf_ptr);
1131c8963ea4SRex Zhu }
1132c8963ea4SRex Zhu
amdgpu_ucode_init_bo(struct amdgpu_device * adev)1133c8963ea4SRex Zhu int amdgpu_ucode_init_bo(struct amdgpu_device *adev)
1134c8963ea4SRex Zhu {
1135c8963ea4SRex Zhu uint64_t fw_offset = 0;
1136c8963ea4SRex Zhu int i;
1137c8963ea4SRex Zhu struct amdgpu_firmware_info *ucode = NULL;
1138c8963ea4SRex Zhu
1139c8963ea4SRex Zhu /* for baremetal, the ucode is allocated in gtt, so don't need to fill the bo when reset/suspend */
114053b3f8f4SDennis Li if (!amdgpu_sriov_vf(adev) && (amdgpu_in_reset(adev) || adev->in_suspend))
1141c8963ea4SRex Zhu return 0;
1142e635ee07SHuang Rui /*
1143e635ee07SHuang Rui * if SMU loaded firmware, it needn't add SMC, UVD, and VCE
1144e635ee07SHuang Rui * ucode info here
1145e635ee07SHuang Rui */
1146bc108ec7STrigger Huang if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
1147bc108ec7STrigger Huang if (amdgpu_sriov_vf(adev))
1148bc108ec7STrigger Huang adev->firmware.max_ucodes = AMDGPU_UCODE_ID_MAXIMUM - 3;
1149e635ee07SHuang Rui else
1150bc108ec7STrigger Huang adev->firmware.max_ucodes = AMDGPU_UCODE_ID_MAXIMUM - 4;
1151bc108ec7STrigger Huang } else {
11522445b227SHuang Rui adev->firmware.max_ucodes = AMDGPU_UCODE_ID_MAXIMUM;
1153bc108ec7STrigger Huang }
1154e635ee07SHuang Rui
11552445b227SHuang Rui for (i = 0; i < adev->firmware.max_ucodes; i++) {
1156d38ceaf9SAlex Deucher ucode = &adev->firmware.ucode[i];
1157d38ceaf9SAlex Deucher if (ucode->fw) {
1158d59c026bSMonk Liu amdgpu_ucode_init_single_fw(adev, ucode, adev->firmware.fw_buf_mc + fw_offset,
1159d59c026bSMonk Liu adev->firmware.fw_buf_ptr + fw_offset);
11602445b227SHuang Rui if (i == AMDGPU_UCODE_ID_CP_MEC1 &&
11612445b227SHuang Rui adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
11624c2b2453SMonk Liu const struct gfx_firmware_header_v1_0 *cp_hdr;
1163e03f04b8SSrinivasan Shanmugam
11644c2b2453SMonk Liu cp_hdr = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
1165d59c026bSMonk Liu amdgpu_ucode_patch_jt(ucode, adev->firmware.fw_buf_mc + fw_offset,
1166d59c026bSMonk Liu adev->firmware.fw_buf_ptr + fw_offset);
11674c2b2453SMonk Liu fw_offset += ALIGN(le32_to_cpu(cp_hdr->jt_size) << 2, PAGE_SIZE);
11684c2b2453SMonk Liu }
11692445b227SHuang Rui fw_offset += ALIGN(ucode->ucode_size, PAGE_SIZE);
1170d38ceaf9SAlex Deucher }
1171d38ceaf9SAlex Deucher }
1172fd506558SHuang Rui return 0;
1173d38ceaf9SAlex Deucher }
11741d5eee7dSLikun Gao
amdgpu_ucode_legacy_naming(struct amdgpu_device * adev,int block_type)117554a3e032SMario Limonciello static const char *amdgpu_ucode_legacy_naming(struct amdgpu_device *adev, int block_type)
117654a3e032SMario Limonciello {
117754a3e032SMario Limonciello if (block_type == MP0_HWIP) {
11784e8303cfSLijo Lazar switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
117954a3e032SMario Limonciello case IP_VERSION(9, 0, 0):
118054a3e032SMario Limonciello switch (adev->asic_type) {
118154a3e032SMario Limonciello case CHIP_VEGA10:
118254a3e032SMario Limonciello return "vega10";
118354a3e032SMario Limonciello case CHIP_VEGA12:
118454a3e032SMario Limonciello return "vega12";
118554a3e032SMario Limonciello default:
118654a3e032SMario Limonciello return NULL;
118754a3e032SMario Limonciello }
118854a3e032SMario Limonciello case IP_VERSION(10, 0, 0):
118954a3e032SMario Limonciello case IP_VERSION(10, 0, 1):
119054a3e032SMario Limonciello if (adev->asic_type == CHIP_RAVEN) {
119154a3e032SMario Limonciello if (adev->apu_flags & AMD_APU_IS_RAVEN2)
119254a3e032SMario Limonciello return "raven2";
119354a3e032SMario Limonciello else if (adev->apu_flags & AMD_APU_IS_PICASSO)
119454a3e032SMario Limonciello return "picasso";
119554a3e032SMario Limonciello return "raven";
119654a3e032SMario Limonciello }
119754a3e032SMario Limonciello break;
119854a3e032SMario Limonciello case IP_VERSION(11, 0, 0):
119954a3e032SMario Limonciello return "navi10";
120054a3e032SMario Limonciello case IP_VERSION(11, 0, 2):
120154a3e032SMario Limonciello return "vega20";
12020604897bSMario Limonciello case IP_VERSION(11, 0, 3):
12030604897bSMario Limonciello return "renoir";
120454a3e032SMario Limonciello case IP_VERSION(11, 0, 4):
120554a3e032SMario Limonciello return "arcturus";
120654a3e032SMario Limonciello case IP_VERSION(11, 0, 5):
120754a3e032SMario Limonciello return "navi14";
120854a3e032SMario Limonciello case IP_VERSION(11, 0, 7):
120954a3e032SMario Limonciello return "sienna_cichlid";
121054a3e032SMario Limonciello case IP_VERSION(11, 0, 9):
121154a3e032SMario Limonciello return "navi12";
121254a3e032SMario Limonciello case IP_VERSION(11, 0, 11):
121354a3e032SMario Limonciello return "navy_flounder";
121454a3e032SMario Limonciello case IP_VERSION(11, 0, 12):
121554a3e032SMario Limonciello return "dimgrey_cavefish";
121654a3e032SMario Limonciello case IP_VERSION(11, 0, 13):
121754a3e032SMario Limonciello return "beige_goby";
121854a3e032SMario Limonciello case IP_VERSION(11, 5, 0):
1219*16a5a8feSYing Li case IP_VERSION(11, 5, 2):
122054a3e032SMario Limonciello return "vangogh";
122154a3e032SMario Limonciello case IP_VERSION(12, 0, 1):
122254a3e032SMario Limonciello return "green_sardine";
122354a3e032SMario Limonciello case IP_VERSION(13, 0, 2):
122454a3e032SMario Limonciello return "aldebaran";
122554a3e032SMario Limonciello case IP_VERSION(13, 0, 1):
122654a3e032SMario Limonciello case IP_VERSION(13, 0, 3):
122754a3e032SMario Limonciello return "yellow_carp";
122854a3e032SMario Limonciello }
122954a3e032SMario Limonciello } else if (block_type == MP1_HWIP) {
12304e8303cfSLijo Lazar switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
123154a3e032SMario Limonciello case IP_VERSION(9, 0, 0):
123254a3e032SMario Limonciello case IP_VERSION(10, 0, 0):
123354a3e032SMario Limonciello case IP_VERSION(10, 0, 1):
123454a3e032SMario Limonciello case IP_VERSION(11, 0, 2):
123554a3e032SMario Limonciello if (adev->asic_type == CHIP_ARCTURUS)
123654a3e032SMario Limonciello return "arcturus_smc";
123754a3e032SMario Limonciello return NULL;
123854a3e032SMario Limonciello case IP_VERSION(11, 0, 0):
123954a3e032SMario Limonciello return "navi10_smc";
124054a3e032SMario Limonciello case IP_VERSION(11, 0, 5):
124154a3e032SMario Limonciello return "navi14_smc";
124254a3e032SMario Limonciello case IP_VERSION(11, 0, 9):
124354a3e032SMario Limonciello return "navi12_smc";
124454a3e032SMario Limonciello case IP_VERSION(11, 0, 7):
124554a3e032SMario Limonciello return "sienna_cichlid_smc";
124654a3e032SMario Limonciello case IP_VERSION(11, 0, 11):
124754a3e032SMario Limonciello return "navy_flounder_smc";
124854a3e032SMario Limonciello case IP_VERSION(11, 0, 12):
124954a3e032SMario Limonciello return "dimgrey_cavefish_smc";
125054a3e032SMario Limonciello case IP_VERSION(11, 0, 13):
125154a3e032SMario Limonciello return "beige_goby_smc";
125254a3e032SMario Limonciello case IP_VERSION(13, 0, 2):
125354a3e032SMario Limonciello return "aldebaran_smc";
125454a3e032SMario Limonciello }
125554a3e032SMario Limonciello } else if (block_type == SDMA0_HWIP) {
12564e8303cfSLijo Lazar switch (amdgpu_ip_version(adev, SDMA0_HWIP, 0)) {
125754a3e032SMario Limonciello case IP_VERSION(4, 0, 0):
125854a3e032SMario Limonciello return "vega10_sdma";
125954a3e032SMario Limonciello case IP_VERSION(4, 0, 1):
126054a3e032SMario Limonciello return "vega12_sdma";
126154a3e032SMario Limonciello case IP_VERSION(4, 1, 0):
126254a3e032SMario Limonciello case IP_VERSION(4, 1, 1):
126354a3e032SMario Limonciello if (adev->apu_flags & AMD_APU_IS_RAVEN2)
126454a3e032SMario Limonciello return "raven2_sdma";
126554a3e032SMario Limonciello else if (adev->apu_flags & AMD_APU_IS_PICASSO)
126654a3e032SMario Limonciello return "picasso_sdma";
126754a3e032SMario Limonciello return "raven_sdma";
126854a3e032SMario Limonciello case IP_VERSION(4, 1, 2):
126954a3e032SMario Limonciello if (adev->apu_flags & AMD_APU_IS_RENOIR)
127054a3e032SMario Limonciello return "renoir_sdma";
127154a3e032SMario Limonciello return "green_sardine_sdma";
127254a3e032SMario Limonciello case IP_VERSION(4, 2, 0):
127354a3e032SMario Limonciello return "vega20_sdma";
127454a3e032SMario Limonciello case IP_VERSION(4, 2, 2):
127554a3e032SMario Limonciello return "arcturus_sdma";
127654a3e032SMario Limonciello case IP_VERSION(4, 4, 0):
127754a3e032SMario Limonciello return "aldebaran_sdma";
127854a3e032SMario Limonciello case IP_VERSION(5, 0, 0):
127954a3e032SMario Limonciello return "navi10_sdma";
128054a3e032SMario Limonciello case IP_VERSION(5, 0, 1):
128154a3e032SMario Limonciello return "cyan_skillfish2_sdma";
128254a3e032SMario Limonciello case IP_VERSION(5, 0, 2):
128354a3e032SMario Limonciello return "navi14_sdma";
128454a3e032SMario Limonciello case IP_VERSION(5, 0, 5):
128554a3e032SMario Limonciello return "navi12_sdma";
128654a3e032SMario Limonciello case IP_VERSION(5, 2, 0):
128754a3e032SMario Limonciello return "sienna_cichlid_sdma";
128854a3e032SMario Limonciello case IP_VERSION(5, 2, 2):
128954a3e032SMario Limonciello return "navy_flounder_sdma";
129054a3e032SMario Limonciello case IP_VERSION(5, 2, 4):
129154a3e032SMario Limonciello return "dimgrey_cavefish_sdma";
129254a3e032SMario Limonciello case IP_VERSION(5, 2, 5):
129354a3e032SMario Limonciello return "beige_goby_sdma";
129454a3e032SMario Limonciello case IP_VERSION(5, 2, 3):
129554a3e032SMario Limonciello return "yellow_carp_sdma";
129654a3e032SMario Limonciello case IP_VERSION(5, 2, 1):
129754a3e032SMario Limonciello return "vangogh_sdma";
129854a3e032SMario Limonciello }
129954a3e032SMario Limonciello } else if (block_type == UVD_HWIP) {
13004e8303cfSLijo Lazar switch (amdgpu_ip_version(adev, UVD_HWIP, 0)) {
130154a3e032SMario Limonciello case IP_VERSION(1, 0, 0):
130254a3e032SMario Limonciello case IP_VERSION(1, 0, 1):
130354a3e032SMario Limonciello if (adev->apu_flags & AMD_APU_IS_RAVEN2)
130454a3e032SMario Limonciello return "raven2_vcn";
130554a3e032SMario Limonciello else if (adev->apu_flags & AMD_APU_IS_PICASSO)
130654a3e032SMario Limonciello return "picasso_vcn";
130754a3e032SMario Limonciello return "raven_vcn";
130854a3e032SMario Limonciello case IP_VERSION(2, 5, 0):
130954a3e032SMario Limonciello return "arcturus_vcn";
131054a3e032SMario Limonciello case IP_VERSION(2, 2, 0):
131154a3e032SMario Limonciello if (adev->apu_flags & AMD_APU_IS_RENOIR)
131254a3e032SMario Limonciello return "renoir_vcn";
131354a3e032SMario Limonciello return "green_sardine_vcn";
131454a3e032SMario Limonciello case IP_VERSION(2, 6, 0):
131554a3e032SMario Limonciello return "aldebaran_vcn";
131654a3e032SMario Limonciello case IP_VERSION(2, 0, 0):
131754a3e032SMario Limonciello return "navi10_vcn";
131854a3e032SMario Limonciello case IP_VERSION(2, 0, 2):
131954a3e032SMario Limonciello if (adev->asic_type == CHIP_NAVI12)
132054a3e032SMario Limonciello return "navi12_vcn";
132154a3e032SMario Limonciello return "navi14_vcn";
132254a3e032SMario Limonciello case IP_VERSION(3, 0, 0):
132354a3e032SMario Limonciello case IP_VERSION(3, 0, 64):
132454a3e032SMario Limonciello case IP_VERSION(3, 0, 192):
13254e8303cfSLijo Lazar if (amdgpu_ip_version(adev, GC_HWIP, 0) ==
13264e8303cfSLijo Lazar IP_VERSION(10, 3, 0))
132754a3e032SMario Limonciello return "sienna_cichlid_vcn";
132854a3e032SMario Limonciello return "navy_flounder_vcn";
132954a3e032SMario Limonciello case IP_VERSION(3, 0, 2):
133054a3e032SMario Limonciello return "vangogh_vcn";
133154a3e032SMario Limonciello case IP_VERSION(3, 0, 16):
133254a3e032SMario Limonciello return "dimgrey_cavefish_vcn";
133354a3e032SMario Limonciello case IP_VERSION(3, 0, 33):
133454a3e032SMario Limonciello return "beige_goby_vcn";
133554a3e032SMario Limonciello case IP_VERSION(3, 1, 1):
133654a3e032SMario Limonciello return "yellow_carp_vcn";
133754a3e032SMario Limonciello }
133854a3e032SMario Limonciello } else if (block_type == GC_HWIP) {
13394e8303cfSLijo Lazar switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
134054a3e032SMario Limonciello case IP_VERSION(9, 0, 1):
134154a3e032SMario Limonciello return "vega10";
134254a3e032SMario Limonciello case IP_VERSION(9, 2, 1):
134354a3e032SMario Limonciello return "vega12";
134454a3e032SMario Limonciello case IP_VERSION(9, 4, 0):
134554a3e032SMario Limonciello return "vega20";
134654a3e032SMario Limonciello case IP_VERSION(9, 2, 2):
134754a3e032SMario Limonciello case IP_VERSION(9, 1, 0):
134854a3e032SMario Limonciello if (adev->apu_flags & AMD_APU_IS_RAVEN2)
134954a3e032SMario Limonciello return "raven2";
135054a3e032SMario Limonciello else if (adev->apu_flags & AMD_APU_IS_PICASSO)
135154a3e032SMario Limonciello return "picasso";
135254a3e032SMario Limonciello return "raven";
135354a3e032SMario Limonciello case IP_VERSION(9, 4, 1):
135454a3e032SMario Limonciello return "arcturus";
135554a3e032SMario Limonciello case IP_VERSION(9, 3, 0):
135654a3e032SMario Limonciello if (adev->apu_flags & AMD_APU_IS_RENOIR)
135754a3e032SMario Limonciello return "renoir";
135854a3e032SMario Limonciello return "green_sardine";
135954a3e032SMario Limonciello case IP_VERSION(9, 4, 2):
136054a3e032SMario Limonciello return "aldebaran";
136154a3e032SMario Limonciello case IP_VERSION(10, 1, 10):
136254a3e032SMario Limonciello return "navi10";
136354a3e032SMario Limonciello case IP_VERSION(10, 1, 1):
136454a3e032SMario Limonciello return "navi14";
136554a3e032SMario Limonciello case IP_VERSION(10, 1, 2):
136654a3e032SMario Limonciello return "navi12";
136754a3e032SMario Limonciello case IP_VERSION(10, 3, 0):
136854a3e032SMario Limonciello return "sienna_cichlid";
136954a3e032SMario Limonciello case IP_VERSION(10, 3, 2):
137054a3e032SMario Limonciello return "navy_flounder";
137154a3e032SMario Limonciello case IP_VERSION(10, 3, 1):
137254a3e032SMario Limonciello return "vangogh";
137354a3e032SMario Limonciello case IP_VERSION(10, 3, 4):
137454a3e032SMario Limonciello return "dimgrey_cavefish";
137554a3e032SMario Limonciello case IP_VERSION(10, 3, 5):
137654a3e032SMario Limonciello return "beige_goby";
137754a3e032SMario Limonciello case IP_VERSION(10, 3, 3):
137854a3e032SMario Limonciello return "yellow_carp";
137954a3e032SMario Limonciello case IP_VERSION(10, 1, 3):
138054a3e032SMario Limonciello case IP_VERSION(10, 1, 4):
138154a3e032SMario Limonciello return "cyan_skillfish2";
138254a3e032SMario Limonciello }
138354a3e032SMario Limonciello }
138454a3e032SMario Limonciello return NULL;
138554a3e032SMario Limonciello }
138654a3e032SMario Limonciello
amdgpu_ucode_ip_version_decode(struct amdgpu_device * adev,int block_type,char * ucode_prefix,int len)13871d5eee7dSLikun Gao void amdgpu_ucode_ip_version_decode(struct amdgpu_device *adev, int block_type, char *ucode_prefix, int len)
13881d5eee7dSLikun Gao {
13891d5eee7dSLikun Gao int maj, min, rev;
13901d5eee7dSLikun Gao char *ip_name;
139154a3e032SMario Limonciello const char *legacy;
13924e8303cfSLijo Lazar uint32_t version = amdgpu_ip_version(adev, block_type, 0);
13931d5eee7dSLikun Gao
139454a3e032SMario Limonciello legacy = amdgpu_ucode_legacy_naming(adev, block_type);
139554a3e032SMario Limonciello if (legacy) {
139654a3e032SMario Limonciello snprintf(ucode_prefix, len, "%s", legacy);
139754a3e032SMario Limonciello return;
139854a3e032SMario Limonciello }
139954a3e032SMario Limonciello
14001d5eee7dSLikun Gao switch (block_type) {
14011d5eee7dSLikun Gao case GC_HWIP:
14021d5eee7dSLikun Gao ip_name = "gc";
14031d5eee7dSLikun Gao break;
14041d5eee7dSLikun Gao case SDMA0_HWIP:
14051d5eee7dSLikun Gao ip_name = "sdma";
14061d5eee7dSLikun Gao break;
14071d5eee7dSLikun Gao case MP0_HWIP:
14081d5eee7dSLikun Gao ip_name = "psp";
14091d5eee7dSLikun Gao break;
14101d5eee7dSLikun Gao case MP1_HWIP:
14111d5eee7dSLikun Gao ip_name = "smu";
14121d5eee7dSLikun Gao break;
14131d5eee7dSLikun Gao case UVD_HWIP:
14141d5eee7dSLikun Gao ip_name = "vcn";
14151d5eee7dSLikun Gao break;
1416ce7b59c1SLang Yu case VPE_HWIP:
1417ce7b59c1SLang Yu ip_name = "vpe";
1418ce7b59c1SLang Yu break;
14198fcbfd53SPratap Nirujogi case ISP_HWIP:
14208fcbfd53SPratap Nirujogi ip_name = "isp";
14218fcbfd53SPratap Nirujogi break;
14221d5eee7dSLikun Gao default:
14231d5eee7dSLikun Gao BUG();
14241d5eee7dSLikun Gao }
14251d5eee7dSLikun Gao
14261d5eee7dSLikun Gao maj = IP_VERSION_MAJ(version);
14271d5eee7dSLikun Gao min = IP_VERSION_MIN(version);
14281d5eee7dSLikun Gao rev = IP_VERSION_REV(version);
14291d5eee7dSLikun Gao
14301d5eee7dSLikun Gao snprintf(ucode_prefix, len, "%s_%d_%d_%d", ip_name, maj, min, rev);
14311d5eee7dSLikun Gao }
14322210af50SMario Limonciello
14332210af50SMario Limonciello /*
14342210af50SMario Limonciello * amdgpu_ucode_request - Fetch and validate amdgpu microcode
14352210af50SMario Limonciello *
14362210af50SMario Limonciello * @adev: amdgpu device
14372210af50SMario Limonciello * @fw: pointer to load firmware to
1438ea5d4934SMario Limonciello * @required: whether the firmware is required
14391bfe5e77SYang Wang * @fmt: firmware name format string
14401bfe5e77SYang Wang * @...: variable arguments
14412210af50SMario Limonciello *
14422210af50SMario Limonciello * This is a helper that will use request_firmware and amdgpu_ucode_validate
14432210af50SMario Limonciello * to load and run basic validation on firmware. If the load fails, remap
14442210af50SMario Limonciello * the error code to -ENODEV, so that early_init functions will fail to load.
14452210af50SMario Limonciello */
amdgpu_ucode_request(struct amdgpu_device * adev,const struct firmware ** fw,enum amdgpu_ucode_required required,const char * fmt,...)14462210af50SMario Limonciello int amdgpu_ucode_request(struct amdgpu_device *adev, const struct firmware **fw,
1447ea5d4934SMario Limonciello enum amdgpu_ucode_required required, const char *fmt, ...)
14482210af50SMario Limonciello {
14491bfe5e77SYang Wang char fname[AMDGPU_UCODE_NAME_MAX];
14501bfe5e77SYang Wang va_list ap;
14511bfe5e77SYang Wang int r;
14522210af50SMario Limonciello
14531bfe5e77SYang Wang va_start(ap, fmt);
14541bfe5e77SYang Wang r = vsnprintf(fname, sizeof(fname), fmt, ap);
14551bfe5e77SYang Wang va_end(ap);
14561bfe5e77SYang Wang if (r == sizeof(fname)) {
14571bfe5e77SYang Wang dev_warn(adev->dev, "amdgpu firmware name buffer overflow\n");
14581bfe5e77SYang Wang return -EOVERFLOW;
14591bfe5e77SYang Wang }
14601bfe5e77SYang Wang
1461ea5d4934SMario Limonciello if (required == AMDGPU_UCODE_REQUIRED)
14621bfe5e77SYang Wang r = request_firmware(fw, fname, adev->dev);
1463b6e6871aSMario Limonciello else {
1464ea5d4934SMario Limonciello r = firmware_request_nowarn(fw, fname, adev->dev);
14651bfe5e77SYang Wang if (r)
1466b6e6871aSMario Limonciello drm_info(&adev->ddev, "Optional firmware \"%s\" was not found\n", fname);
1467b6e6871aSMario Limonciello }
1468b6e6871aSMario Limonciello if (r)
14692210af50SMario Limonciello return -ENODEV;
147013a1851fSSrinivasan Shanmugam
14711bfe5e77SYang Wang r = amdgpu_ucode_validate(*fw);
1472d2382f29SPrike Liang if (r)
1473d2382f29SPrike Liang /*
1474d2382f29SPrike Liang * The amdgpu_ucode_request() should be paired with amdgpu_ucode_release()
1475d2382f29SPrike Liang * regardless of success/failure, and the amdgpu_ucode_release() takes care of
1476d2382f29SPrike Liang * firmware release and need to avoid redundant release FW operation here.
1477d2382f29SPrike Liang */
14781bfe5e77SYang Wang dev_dbg(adev->dev, "\"%s\" failed to validate\n", fname);
14792210af50SMario Limonciello
14801bfe5e77SYang Wang return r;
14812210af50SMario Limonciello }
14822210af50SMario Limonciello
14832210af50SMario Limonciello /*
14842210af50SMario Limonciello * amdgpu_ucode_release - Release firmware microcode
14852210af50SMario Limonciello *
14862210af50SMario Limonciello * @fw: pointer to firmware to release
14872210af50SMario Limonciello */
amdgpu_ucode_release(const struct firmware ** fw)14882210af50SMario Limonciello void amdgpu_ucode_release(const struct firmware **fw)
14892210af50SMario Limonciello {
14902210af50SMario Limonciello release_firmware(*fw);
14912210af50SMario Limonciello *fw = NULL;
14922210af50SMario Limonciello }
1493