]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h
drm/amdgpu/ucode: add mes firmware file support
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_ucode.h
1 /*
2  * Copyright 2012 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 #ifndef __AMDGPU_UCODE_H__
24 #define __AMDGPU_UCODE_H__
25
26 struct common_firmware_header {
27         uint32_t size_bytes; /* size of the entire header+image(s) in bytes */
28         uint32_t header_size_bytes; /* size of just the header in bytes */
29         uint16_t header_version_major; /* header version */
30         uint16_t header_version_minor; /* header version */
31         uint16_t ip_version_major; /* IP version */
32         uint16_t ip_version_minor; /* IP version */
33         uint32_t ucode_version;
34         uint32_t ucode_size_bytes; /* size of ucode in bytes */
35         uint32_t ucode_array_offset_bytes; /* payload offset from the start of the header */
36         uint32_t crc32;  /* crc32 checksum of the payload */
37 };
38
39 /* version_major=1, version_minor=0 */
40 struct mc_firmware_header_v1_0 {
41         struct common_firmware_header header;
42         uint32_t io_debug_size_bytes; /* size of debug array in dwords */
43         uint32_t io_debug_array_offset_bytes; /* payload offset from the start of the header */
44 };
45
46 /* version_major=1, version_minor=0 */
47 struct smc_firmware_header_v1_0 {
48         struct common_firmware_header header;
49         uint32_t ucode_start_addr;
50 };
51
52 /* version_major=2, version_minor=0 */
53 struct smc_firmware_header_v2_0 {
54         struct smc_firmware_header_v1_0 v1_0;
55         uint32_t ppt_offset_bytes; /* soft pptable offset */
56         uint32_t ppt_size_bytes; /* soft pptable size */
57 };
58
59 struct smc_soft_pptable_entry {
60         uint32_t id;
61         uint32_t ppt_offset_bytes;
62         uint32_t ppt_size_bytes;
63 };
64
65 /* version_major=2, version_minor=1 */
66 struct smc_firmware_header_v2_1 {
67         struct smc_firmware_header_v1_0 v1_0;
68         uint32_t pptable_count;
69         uint32_t pptable_entry_offset;
70 };
71
72 /* version_major=1, version_minor=0 */
73 struct psp_firmware_header_v1_0 {
74         struct common_firmware_header header;
75         uint32_t ucode_feature_version;
76         uint32_t sos_offset_bytes;
77         uint32_t sos_size_bytes;
78 };
79
80 /* version_major=1, version_minor=1 */
81 struct psp_firmware_header_v1_1 {
82         struct psp_firmware_header_v1_0 v1_0;
83         uint32_t toc_header_version;
84         uint32_t toc_offset_bytes;
85         uint32_t toc_size_bytes;
86 };
87
88 /* version_major=1, version_minor=0 */
89 struct ta_firmware_header_v1_0 {
90         struct common_firmware_header header;
91         uint32_t ta_xgmi_ucode_version;
92         uint32_t ta_xgmi_offset_bytes;
93         uint32_t ta_xgmi_size_bytes;
94         uint32_t ta_ras_ucode_version;
95         uint32_t ta_ras_offset_bytes;
96         uint32_t ta_ras_size_bytes;
97 };
98
99 /* version_major=1, version_minor=0 */
100 struct gfx_firmware_header_v1_0 {
101         struct common_firmware_header header;
102         uint32_t ucode_feature_version;
103         uint32_t jt_offset; /* jt location */
104         uint32_t jt_size;  /* size of jt */
105 };
106
107 /* version_major=1, version_minor=0 */
108 struct mes_firmware_header_v1_0 {
109         struct common_firmware_header header;
110         uint32_t mes_ucode_version;
111         uint32_t mes_ucode_size_bytes;
112         uint32_t mes_ucode_offset_bytes;
113         uint32_t mes_ucode_data_version;
114         uint32_t mes_ucode_data_size_bytes;
115         uint32_t mes_ucode_data_offset_bytes;
116         uint32_t mes_uc_start_addr_lo;
117         uint32_t mes_uc_start_addr_hi;
118         uint32_t mes_data_start_addr_lo;
119         uint32_t mes_data_start_addr_hi;
120 };
121
122 /* version_major=1, version_minor=0 */
123 struct rlc_firmware_header_v1_0 {
124         struct common_firmware_header header;
125         uint32_t ucode_feature_version;
126         uint32_t save_and_restore_offset;
127         uint32_t clear_state_descriptor_offset;
128         uint32_t avail_scratch_ram_locations;
129         uint32_t master_pkt_description_offset;
130 };
131
132 /* version_major=2, version_minor=0 */
133 struct rlc_firmware_header_v2_0 {
134         struct common_firmware_header header;
135         uint32_t ucode_feature_version;
136         uint32_t jt_offset; /* jt location */
137         uint32_t jt_size;  /* size of jt */
138         uint32_t save_and_restore_offset;
139         uint32_t clear_state_descriptor_offset;
140         uint32_t avail_scratch_ram_locations;
141         uint32_t reg_restore_list_size;
142         uint32_t reg_list_format_start;
143         uint32_t reg_list_format_separate_start;
144         uint32_t starting_offsets_start;
145         uint32_t reg_list_format_size_bytes; /* size of reg list format array in bytes */
146         uint32_t reg_list_format_array_offset_bytes; /* payload offset from the start of the header */
147         uint32_t reg_list_size_bytes; /* size of reg list array in bytes */
148         uint32_t reg_list_array_offset_bytes; /* payload offset from the start of the header */
149         uint32_t reg_list_format_separate_size_bytes; /* size of reg list format array in bytes */
150         uint32_t reg_list_format_separate_array_offset_bytes; /* payload offset from the start of the header */
151         uint32_t reg_list_separate_size_bytes; /* size of reg list array in bytes */
152         uint32_t reg_list_separate_array_offset_bytes; /* payload offset from the start of the header */
153 };
154
155 /* version_major=2, version_minor=1 */
156 struct rlc_firmware_header_v2_1 {
157         struct rlc_firmware_header_v2_0 v2_0;
158         uint32_t reg_list_format_direct_reg_list_length; /* length of direct reg list format array */
159         uint32_t save_restore_list_cntl_ucode_ver;
160         uint32_t save_restore_list_cntl_feature_ver;
161         uint32_t save_restore_list_cntl_size_bytes;
162         uint32_t save_restore_list_cntl_offset_bytes;
163         uint32_t save_restore_list_gpm_ucode_ver;
164         uint32_t save_restore_list_gpm_feature_ver;
165         uint32_t save_restore_list_gpm_size_bytes;
166         uint32_t save_restore_list_gpm_offset_bytes;
167         uint32_t save_restore_list_srm_ucode_ver;
168         uint32_t save_restore_list_srm_feature_ver;
169         uint32_t save_restore_list_srm_size_bytes;
170         uint32_t save_restore_list_srm_offset_bytes;
171 };
172
173 /* version_major=1, version_minor=0 */
174 struct sdma_firmware_header_v1_0 {
175         struct common_firmware_header header;
176         uint32_t ucode_feature_version;
177         uint32_t ucode_change_version;
178         uint32_t jt_offset; /* jt location */
179         uint32_t jt_size; /* size of jt */
180 };
181
182 /* version_major=1, version_minor=1 */
183 struct sdma_firmware_header_v1_1 {
184         struct sdma_firmware_header_v1_0 v1_0;
185         uint32_t digest_size;
186 };
187
188 /* gpu info payload */
189 struct gpu_info_firmware_v1_0 {
190         uint32_t gc_num_se;
191         uint32_t gc_num_cu_per_sh;
192         uint32_t gc_num_sh_per_se;
193         uint32_t gc_num_rb_per_se;
194         uint32_t gc_num_tccs;
195         uint32_t gc_num_gprs;
196         uint32_t gc_num_max_gs_thds;
197         uint32_t gc_gs_table_depth;
198         uint32_t gc_gsprim_buff_depth;
199         uint32_t gc_parameter_cache_depth;
200         uint32_t gc_double_offchip_lds_buffer;
201         uint32_t gc_wave_size;
202         uint32_t gc_max_waves_per_simd;
203         uint32_t gc_max_scratch_slots_per_cu;
204         uint32_t gc_lds_size;
205 };
206
207 struct gpu_info_firmware_v1_1 {
208         struct gpu_info_firmware_v1_0 v1_0;
209         uint32_t num_sc_per_sh;
210         uint32_t num_packer_per_sc;
211 };
212
213 /* version_major=1, version_minor=0 */
214 struct gpu_info_firmware_header_v1_0 {
215         struct common_firmware_header header;
216         uint16_t version_major; /* version */
217         uint16_t version_minor; /* version */
218 };
219
220 /* version_major=1, version_minor=0 */
221 struct dmcu_firmware_header_v1_0 {
222         struct common_firmware_header header;
223         uint32_t intv_offset_bytes; /* interrupt vectors offset from end of header, in bytes */
224         uint32_t intv_size_bytes;  /* size of interrupt vectors, in bytes */
225 };
226
227 /* header is fixed size */
228 union amdgpu_firmware_header {
229         struct common_firmware_header common;
230         struct mc_firmware_header_v1_0 mc;
231         struct smc_firmware_header_v1_0 smc;
232         struct smc_firmware_header_v2_0 smc_v2_0;
233         struct psp_firmware_header_v1_0 psp;
234         struct psp_firmware_header_v1_1 psp_v1_1;
235         struct ta_firmware_header_v1_0 ta;
236         struct gfx_firmware_header_v1_0 gfx;
237         struct rlc_firmware_header_v1_0 rlc;
238         struct rlc_firmware_header_v2_0 rlc_v2_0;
239         struct rlc_firmware_header_v2_1 rlc_v2_1;
240         struct sdma_firmware_header_v1_0 sdma;
241         struct sdma_firmware_header_v1_1 sdma_v1_1;
242         struct gpu_info_firmware_header_v1_0 gpu_info;
243         struct dmcu_firmware_header_v1_0 dmcu;
244         uint8_t raw[0x100];
245 };
246
247 /*
248  * fw loading support
249  */
250 enum AMDGPU_UCODE_ID {
251         AMDGPU_UCODE_ID_SDMA0 = 0,
252         AMDGPU_UCODE_ID_SDMA1,
253         AMDGPU_UCODE_ID_CP_CE,
254         AMDGPU_UCODE_ID_CP_PFP,
255         AMDGPU_UCODE_ID_CP_ME,
256         AMDGPU_UCODE_ID_CP_MEC1,
257         AMDGPU_UCODE_ID_CP_MEC1_JT,
258         AMDGPU_UCODE_ID_CP_MEC2,
259         AMDGPU_UCODE_ID_CP_MEC2_JT,
260         AMDGPU_UCODE_ID_CP_MES,
261         AMDGPU_UCODE_ID_CP_MES_DATA,
262         AMDGPU_UCODE_ID_RLC_G,
263         AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL,
264         AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM,
265         AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM,
266         AMDGPU_UCODE_ID_STORAGE,
267         AMDGPU_UCODE_ID_SMC,
268         AMDGPU_UCODE_ID_UVD,
269         AMDGPU_UCODE_ID_UVD1,
270         AMDGPU_UCODE_ID_VCE,
271         AMDGPU_UCODE_ID_VCN,
272         AMDGPU_UCODE_ID_DMCU_ERAM,
273         AMDGPU_UCODE_ID_DMCU_INTV,
274         AMDGPU_UCODE_ID_MAXIMUM,
275 };
276
277 /* engine firmware status */
278 enum AMDGPU_UCODE_STATUS {
279         AMDGPU_UCODE_STATUS_INVALID,
280         AMDGPU_UCODE_STATUS_NOT_LOADED,
281         AMDGPU_UCODE_STATUS_LOADED,
282 };
283
284 enum amdgpu_firmware_load_type {
285         AMDGPU_FW_LOAD_DIRECT = 0,
286         AMDGPU_FW_LOAD_SMU,
287         AMDGPU_FW_LOAD_PSP,
288         AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO,
289 };
290
291 /* conform to smu_ucode_xfer_cz.h */
292 #define AMDGPU_SDMA0_UCODE_LOADED       0x00000001
293 #define AMDGPU_SDMA1_UCODE_LOADED       0x00000002
294 #define AMDGPU_CPCE_UCODE_LOADED        0x00000004
295 #define AMDGPU_CPPFP_UCODE_LOADED       0x00000008
296 #define AMDGPU_CPME_UCODE_LOADED        0x00000010
297 #define AMDGPU_CPMEC1_UCODE_LOADED      0x00000020
298 #define AMDGPU_CPMEC2_UCODE_LOADED      0x00000040
299 #define AMDGPU_CPRLC_UCODE_LOADED       0x00000100
300
301 /* amdgpu firmware info */
302 struct amdgpu_firmware_info {
303         /* ucode ID */
304         enum AMDGPU_UCODE_ID ucode_id;
305         /* request_firmware */
306         const struct firmware *fw;
307         /* starting mc address */
308         uint64_t mc_addr;
309         /* kernel linear address */
310         void *kaddr;
311         /* ucode_size_bytes */
312         uint32_t ucode_size;
313         /* starting tmr mc address */
314         uint32_t tmr_mc_addr_lo;
315         uint32_t tmr_mc_addr_hi;
316 };
317
318 struct amdgpu_firmware {
319         struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
320         enum amdgpu_firmware_load_type load_type;
321         struct amdgpu_bo *fw_buf;
322         unsigned int fw_size;
323         unsigned int max_ucodes;
324         /* firmwares are loaded by psp instead of smu from vega10 */
325         const struct amdgpu_psp_funcs *funcs;
326         struct amdgpu_bo *rbuf;
327         struct mutex mutex;
328
329         /* gpu info firmware data pointer */
330         const struct firmware *gpu_info_fw;
331
332         void *fw_buf_ptr;
333         uint64_t fw_buf_mc;
334 };
335
336 void amdgpu_ucode_print_mc_hdr(const struct common_firmware_header *hdr);
337 void amdgpu_ucode_print_smc_hdr(const struct common_firmware_header *hdr);
338 void amdgpu_ucode_print_gfx_hdr(const struct common_firmware_header *hdr);
339 void amdgpu_ucode_print_rlc_hdr(const struct common_firmware_header *hdr);
340 void amdgpu_ucode_print_sdma_hdr(const struct common_firmware_header *hdr);
341 void amdgpu_ucode_print_psp_hdr(const struct common_firmware_header *hdr);
342 void amdgpu_ucode_print_gpu_info_hdr(const struct common_firmware_header *hdr);
343 int amdgpu_ucode_validate(const struct firmware *fw);
344 bool amdgpu_ucode_hdr_version(union amdgpu_firmware_header *hdr,
345                                 uint16_t hdr_major, uint16_t hdr_minor);
346
347 int amdgpu_ucode_init_bo(struct amdgpu_device *adev);
348 int amdgpu_ucode_create_bo(struct amdgpu_device *adev);
349 int amdgpu_ucode_sysfs_init(struct amdgpu_device *adev);
350 void amdgpu_ucode_free_bo(struct amdgpu_device *adev);
351 void amdgpu_ucode_sysfs_fini(struct amdgpu_device *adev);
352
353 enum amdgpu_firmware_load_type
354 amdgpu_ucode_get_load_type(struct amdgpu_device *adev, int load_type);
355
356 #endif
This page took 0.0523 seconds and 4 git commands to generate.