Merge tag 'drm-xilinx-dpsub-20200718' of git://linuxtv.org/pinchartl/media into drm...
[linux-2.6-microblaze.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 #include "amdgpu_socbb.h"
27
28 struct common_firmware_header {
29         uint32_t size_bytes; /* size of the entire header+image(s) in bytes */
30         uint32_t header_size_bytes; /* size of just the header in bytes */
31         uint16_t header_version_major; /* header version */
32         uint16_t header_version_minor; /* header version */
33         uint16_t ip_version_major; /* IP version */
34         uint16_t ip_version_minor; /* IP version */
35         uint32_t ucode_version;
36         uint32_t ucode_size_bytes; /* size of ucode in bytes */
37         uint32_t ucode_array_offset_bytes; /* payload offset from the start of the header */
38         uint32_t crc32;  /* crc32 checksum of the payload */
39 };
40
41 /* version_major=1, version_minor=0 */
42 struct mc_firmware_header_v1_0 {
43         struct common_firmware_header header;
44         uint32_t io_debug_size_bytes; /* size of debug array in dwords */
45         uint32_t io_debug_array_offset_bytes; /* payload offset from the start of the header */
46 };
47
48 /* version_major=1, version_minor=0 */
49 struct smc_firmware_header_v1_0 {
50         struct common_firmware_header header;
51         uint32_t ucode_start_addr;
52 };
53
54 /* version_major=2, version_minor=0 */
55 struct smc_firmware_header_v2_0 {
56         struct smc_firmware_header_v1_0 v1_0;
57         uint32_t ppt_offset_bytes; /* soft pptable offset */
58         uint32_t ppt_size_bytes; /* soft pptable size */
59 };
60
61 struct smc_soft_pptable_entry {
62         uint32_t id;
63         uint32_t ppt_offset_bytes;
64         uint32_t ppt_size_bytes;
65 };
66
67 /* version_major=2, version_minor=1 */
68 struct smc_firmware_header_v2_1 {
69         struct smc_firmware_header_v1_0 v1_0;
70         uint32_t pptable_count;
71         uint32_t pptable_entry_offset;
72 };
73
74 /* version_major=1, version_minor=0 */
75 struct psp_firmware_header_v1_0 {
76         struct common_firmware_header header;
77         uint32_t ucode_feature_version;
78         uint32_t sos_offset_bytes;
79         uint32_t sos_size_bytes;
80 };
81
82 /* version_major=1, version_minor=1 */
83 struct psp_firmware_header_v1_1 {
84         struct psp_firmware_header_v1_0 v1_0;
85         uint32_t toc_header_version;
86         uint32_t toc_offset_bytes;
87         uint32_t toc_size_bytes;
88         uint32_t kdb_header_version;
89         uint32_t kdb_offset_bytes;
90         uint32_t kdb_size_bytes;
91 };
92
93 /* version_major=1, version_minor=2 */
94 struct psp_firmware_header_v1_2 {
95         struct psp_firmware_header_v1_0 v1_0;
96         uint32_t reserve[3];
97         uint32_t kdb_header_version;
98         uint32_t kdb_offset_bytes;
99         uint32_t kdb_size_bytes;
100 };
101
102 /* version_major=1, version_minor=3 */
103 struct psp_firmware_header_v1_3 {
104         struct psp_firmware_header_v1_1 v1_1;
105         uint32_t spl_header_version;
106         uint32_t spl_offset_bytes;
107         uint32_t spl_size_bytes;
108 };
109
110 /* version_major=1, version_minor=0 */
111 struct ta_firmware_header_v1_0 {
112         struct common_firmware_header header;
113         uint32_t ta_xgmi_ucode_version;
114         uint32_t ta_xgmi_offset_bytes;
115         uint32_t ta_xgmi_size_bytes;
116         uint32_t ta_ras_ucode_version;
117         uint32_t ta_ras_offset_bytes;
118         uint32_t ta_ras_size_bytes;
119         uint32_t ta_hdcp_ucode_version;
120         uint32_t ta_hdcp_offset_bytes;
121         uint32_t ta_hdcp_size_bytes;
122         uint32_t ta_dtm_ucode_version;
123         uint32_t ta_dtm_offset_bytes;
124         uint32_t ta_dtm_size_bytes;
125 };
126
127 /* version_major=1, version_minor=0 */
128 struct gfx_firmware_header_v1_0 {
129         struct common_firmware_header header;
130         uint32_t ucode_feature_version;
131         uint32_t jt_offset; /* jt location */
132         uint32_t jt_size;  /* size of jt */
133 };
134
135 /* version_major=1, version_minor=0 */
136 struct mes_firmware_header_v1_0 {
137         struct common_firmware_header header;
138         uint32_t mes_ucode_version;
139         uint32_t mes_ucode_size_bytes;
140         uint32_t mes_ucode_offset_bytes;
141         uint32_t mes_ucode_data_version;
142         uint32_t mes_ucode_data_size_bytes;
143         uint32_t mes_ucode_data_offset_bytes;
144         uint32_t mes_uc_start_addr_lo;
145         uint32_t mes_uc_start_addr_hi;
146         uint32_t mes_data_start_addr_lo;
147         uint32_t mes_data_start_addr_hi;
148 };
149
150 /* version_major=1, version_minor=0 */
151 struct rlc_firmware_header_v1_0 {
152         struct common_firmware_header header;
153         uint32_t ucode_feature_version;
154         uint32_t save_and_restore_offset;
155         uint32_t clear_state_descriptor_offset;
156         uint32_t avail_scratch_ram_locations;
157         uint32_t master_pkt_description_offset;
158 };
159
160 /* version_major=2, version_minor=0 */
161 struct rlc_firmware_header_v2_0 {
162         struct common_firmware_header header;
163         uint32_t ucode_feature_version;
164         uint32_t jt_offset; /* jt location */
165         uint32_t jt_size;  /* size of jt */
166         uint32_t save_and_restore_offset;
167         uint32_t clear_state_descriptor_offset;
168         uint32_t avail_scratch_ram_locations;
169         uint32_t reg_restore_list_size;
170         uint32_t reg_list_format_start;
171         uint32_t reg_list_format_separate_start;
172         uint32_t starting_offsets_start;
173         uint32_t reg_list_format_size_bytes; /* size of reg list format array in bytes */
174         uint32_t reg_list_format_array_offset_bytes; /* payload offset from the start of the header */
175         uint32_t reg_list_size_bytes; /* size of reg list array in bytes */
176         uint32_t reg_list_array_offset_bytes; /* payload offset from the start of the header */
177         uint32_t reg_list_format_separate_size_bytes; /* size of reg list format array in bytes */
178         uint32_t reg_list_format_separate_array_offset_bytes; /* payload offset from the start of the header */
179         uint32_t reg_list_separate_size_bytes; /* size of reg list array in bytes */
180         uint32_t reg_list_separate_array_offset_bytes; /* payload offset from the start of the header */
181 };
182
183 /* version_major=2, version_minor=1 */
184 struct rlc_firmware_header_v2_1 {
185         struct rlc_firmware_header_v2_0 v2_0;
186         uint32_t reg_list_format_direct_reg_list_length; /* length of direct reg list format array */
187         uint32_t save_restore_list_cntl_ucode_ver;
188         uint32_t save_restore_list_cntl_feature_ver;
189         uint32_t save_restore_list_cntl_size_bytes;
190         uint32_t save_restore_list_cntl_offset_bytes;
191         uint32_t save_restore_list_gpm_ucode_ver;
192         uint32_t save_restore_list_gpm_feature_ver;
193         uint32_t save_restore_list_gpm_size_bytes;
194         uint32_t save_restore_list_gpm_offset_bytes;
195         uint32_t save_restore_list_srm_ucode_ver;
196         uint32_t save_restore_list_srm_feature_ver;
197         uint32_t save_restore_list_srm_size_bytes;
198         uint32_t save_restore_list_srm_offset_bytes;
199 };
200
201 /* version_major=1, version_minor=0 */
202 struct sdma_firmware_header_v1_0 {
203         struct common_firmware_header header;
204         uint32_t ucode_feature_version;
205         uint32_t ucode_change_version;
206         uint32_t jt_offset; /* jt location */
207         uint32_t jt_size; /* size of jt */
208 };
209
210 /* version_major=1, version_minor=1 */
211 struct sdma_firmware_header_v1_1 {
212         struct sdma_firmware_header_v1_0 v1_0;
213         uint32_t digest_size;
214 };
215
216 /* gpu info payload */
217 struct gpu_info_firmware_v1_0 {
218         uint32_t gc_num_se;
219         uint32_t gc_num_cu_per_sh;
220         uint32_t gc_num_sh_per_se;
221         uint32_t gc_num_rb_per_se;
222         uint32_t gc_num_tccs;
223         uint32_t gc_num_gprs;
224         uint32_t gc_num_max_gs_thds;
225         uint32_t gc_gs_table_depth;
226         uint32_t gc_gsprim_buff_depth;
227         uint32_t gc_parameter_cache_depth;
228         uint32_t gc_double_offchip_lds_buffer;
229         uint32_t gc_wave_size;
230         uint32_t gc_max_waves_per_simd;
231         uint32_t gc_max_scratch_slots_per_cu;
232         uint32_t gc_lds_size;
233 };
234
235 struct gpu_info_firmware_v1_1 {
236         struct gpu_info_firmware_v1_0 v1_0;
237         uint32_t num_sc_per_sh;
238         uint32_t num_packer_per_sc;
239 };
240
241 /* gpu info payload
242  * version_major=1, version_minor=1 */
243 struct gpu_info_firmware_v1_2 {
244         struct gpu_info_firmware_v1_1 v1_1;
245         struct gpu_info_soc_bounding_box_v1_0 soc_bounding_box;
246 };
247
248 /* version_major=1, version_minor=0 */
249 struct gpu_info_firmware_header_v1_0 {
250         struct common_firmware_header header;
251         uint16_t version_major; /* version */
252         uint16_t version_minor; /* version */
253 };
254
255 /* version_major=1, version_minor=0 */
256 struct dmcu_firmware_header_v1_0 {
257         struct common_firmware_header header;
258         uint32_t intv_offset_bytes; /* interrupt vectors offset from end of header, in bytes */
259         uint32_t intv_size_bytes;  /* size of interrupt vectors, in bytes */
260 };
261
262 /* version_major=1, version_minor=0 */
263 struct dmcub_firmware_header_v1_0 {
264         struct common_firmware_header header;
265         uint32_t inst_const_bytes; /* size of instruction region, in bytes */
266         uint32_t bss_data_bytes; /* size of bss/data region, in bytes */
267 };
268
269 /* header is fixed size */
270 union amdgpu_firmware_header {
271         struct common_firmware_header common;
272         struct mc_firmware_header_v1_0 mc;
273         struct smc_firmware_header_v1_0 smc;
274         struct smc_firmware_header_v2_0 smc_v2_0;
275         struct psp_firmware_header_v1_0 psp;
276         struct psp_firmware_header_v1_1 psp_v1_1;
277         struct psp_firmware_header_v1_3 psp_v1_3;
278         struct ta_firmware_header_v1_0 ta;
279         struct gfx_firmware_header_v1_0 gfx;
280         struct rlc_firmware_header_v1_0 rlc;
281         struct rlc_firmware_header_v2_0 rlc_v2_0;
282         struct rlc_firmware_header_v2_1 rlc_v2_1;
283         struct sdma_firmware_header_v1_0 sdma;
284         struct sdma_firmware_header_v1_1 sdma_v1_1;
285         struct gpu_info_firmware_header_v1_0 gpu_info;
286         struct dmcu_firmware_header_v1_0 dmcu;
287         struct dmcub_firmware_header_v1_0 dmcub;
288         uint8_t raw[0x100];
289 };
290
291 /*
292  * fw loading support
293  */
294 enum AMDGPU_UCODE_ID {
295         AMDGPU_UCODE_ID_SDMA0 = 0,
296         AMDGPU_UCODE_ID_SDMA1,
297         AMDGPU_UCODE_ID_SDMA2,
298         AMDGPU_UCODE_ID_SDMA3,
299         AMDGPU_UCODE_ID_SDMA4,
300         AMDGPU_UCODE_ID_SDMA5,
301         AMDGPU_UCODE_ID_SDMA6,
302         AMDGPU_UCODE_ID_SDMA7,
303         AMDGPU_UCODE_ID_CP_CE,
304         AMDGPU_UCODE_ID_CP_PFP,
305         AMDGPU_UCODE_ID_CP_ME,
306         AMDGPU_UCODE_ID_CP_MEC1,
307         AMDGPU_UCODE_ID_CP_MEC1_JT,
308         AMDGPU_UCODE_ID_CP_MEC2,
309         AMDGPU_UCODE_ID_CP_MEC2_JT,
310         AMDGPU_UCODE_ID_CP_MES,
311         AMDGPU_UCODE_ID_CP_MES_DATA,
312         AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL,
313         AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM,
314         AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM,
315         AMDGPU_UCODE_ID_RLC_G,
316         AMDGPU_UCODE_ID_STORAGE,
317         AMDGPU_UCODE_ID_SMC,
318         AMDGPU_UCODE_ID_UVD,
319         AMDGPU_UCODE_ID_UVD1,
320         AMDGPU_UCODE_ID_VCE,
321         AMDGPU_UCODE_ID_VCN,
322         AMDGPU_UCODE_ID_VCN1,
323         AMDGPU_UCODE_ID_DMCU_ERAM,
324         AMDGPU_UCODE_ID_DMCU_INTV,
325         AMDGPU_UCODE_ID_VCN0_RAM,
326         AMDGPU_UCODE_ID_VCN1_RAM,
327         AMDGPU_UCODE_ID_DMCUB,
328         AMDGPU_UCODE_ID_MAXIMUM,
329 };
330
331 /* engine firmware status */
332 enum AMDGPU_UCODE_STATUS {
333         AMDGPU_UCODE_STATUS_INVALID,
334         AMDGPU_UCODE_STATUS_NOT_LOADED,
335         AMDGPU_UCODE_STATUS_LOADED,
336 };
337
338 enum amdgpu_firmware_load_type {
339         AMDGPU_FW_LOAD_DIRECT = 0,
340         AMDGPU_FW_LOAD_SMU,
341         AMDGPU_FW_LOAD_PSP,
342         AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO,
343 };
344
345 /* conform to smu_ucode_xfer_cz.h */
346 #define AMDGPU_SDMA0_UCODE_LOADED       0x00000001
347 #define AMDGPU_SDMA1_UCODE_LOADED       0x00000002
348 #define AMDGPU_CPCE_UCODE_LOADED        0x00000004
349 #define AMDGPU_CPPFP_UCODE_LOADED       0x00000008
350 #define AMDGPU_CPME_UCODE_LOADED        0x00000010
351 #define AMDGPU_CPMEC1_UCODE_LOADED      0x00000020
352 #define AMDGPU_CPMEC2_UCODE_LOADED      0x00000040
353 #define AMDGPU_CPRLC_UCODE_LOADED       0x00000100
354
355 /* amdgpu firmware info */
356 struct amdgpu_firmware_info {
357         /* ucode ID */
358         enum AMDGPU_UCODE_ID ucode_id;
359         /* request_firmware */
360         const struct firmware *fw;
361         /* starting mc address */
362         uint64_t mc_addr;
363         /* kernel linear address */
364         void *kaddr;
365         /* ucode_size_bytes */
366         uint32_t ucode_size;
367         /* starting tmr mc address */
368         uint32_t tmr_mc_addr_lo;
369         uint32_t tmr_mc_addr_hi;
370 };
371
372 struct amdgpu_firmware {
373         struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
374         enum amdgpu_firmware_load_type load_type;
375         struct amdgpu_bo *fw_buf;
376         unsigned int fw_size;
377         unsigned int max_ucodes;
378         /* firmwares are loaded by psp instead of smu from vega10 */
379         const struct amdgpu_psp_funcs *funcs;
380         struct amdgpu_bo *rbuf;
381         struct mutex mutex;
382
383         /* gpu info firmware data pointer */
384         const struct firmware *gpu_info_fw;
385
386         void *fw_buf_ptr;
387         uint64_t fw_buf_mc;
388 };
389
390 void amdgpu_ucode_print_mc_hdr(const struct common_firmware_header *hdr);
391 void amdgpu_ucode_print_smc_hdr(const struct common_firmware_header *hdr);
392 void amdgpu_ucode_print_gfx_hdr(const struct common_firmware_header *hdr);
393 void amdgpu_ucode_print_rlc_hdr(const struct common_firmware_header *hdr);
394 void amdgpu_ucode_print_sdma_hdr(const struct common_firmware_header *hdr);
395 void amdgpu_ucode_print_psp_hdr(const struct common_firmware_header *hdr);
396 void amdgpu_ucode_print_gpu_info_hdr(const struct common_firmware_header *hdr);
397 int amdgpu_ucode_validate(const struct firmware *fw);
398 bool amdgpu_ucode_hdr_version(union amdgpu_firmware_header *hdr,
399                                 uint16_t hdr_major, uint16_t hdr_minor);
400
401 int amdgpu_ucode_init_bo(struct amdgpu_device *adev);
402 int amdgpu_ucode_create_bo(struct amdgpu_device *adev);
403 int amdgpu_ucode_sysfs_init(struct amdgpu_device *adev);
404 void amdgpu_ucode_free_bo(struct amdgpu_device *adev);
405 void amdgpu_ucode_sysfs_fini(struct amdgpu_device *adev);
406
407 enum amdgpu_firmware_load_type
408 amdgpu_ucode_get_load_type(struct amdgpu_device *adev, int load_type);
409
410 #endif