1 /*
2  * Copyright 2016 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 
24 #include <drm/amdgpu_drm.h>
25 #include "amdgpu.h"
26 #include "atomfirmware.h"
27 #include "amdgpu_atomfirmware.h"
28 #include "atom.h"
29 #include "atombios.h"
30 #include "soc15_hw_ip.h"
31 
32 union firmware_info {
33 	struct atom_firmware_info_v3_1 v31;
34 	struct atom_firmware_info_v3_2 v32;
35 	struct atom_firmware_info_v3_3 v33;
36 	struct atom_firmware_info_v3_4 v34;
37 };
38 
39 /*
40  * Helper function to query firmware capability
41  *
42  * @adev: amdgpu_device pointer
43  *
44  * Return firmware_capability in firmwareinfo table on success or 0 if not
45  */
46 uint32_t amdgpu_atomfirmware_query_firmware_capability(struct amdgpu_device *adev)
47 {
48 	struct amdgpu_mode_info *mode_info = &adev->mode_info;
49 	int index;
50 	u16 data_offset, size;
51 	union firmware_info *firmware_info;
52 	u8 frev, crev;
53 	u32 fw_cap = 0;
54 
55 	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
56 			firmwareinfo);
57 
58 	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context,
59 				index, &size, &frev, &crev, &data_offset)) {
60 		/* support firmware_info 3.1 + */
61 		if ((frev == 3 && crev >=1) || (frev > 3)) {
62 			firmware_info = (union firmware_info *)
63 				(mode_info->atom_context->bios + data_offset);
64 			fw_cap = le32_to_cpu(firmware_info->v31.firmware_capability);
65 		}
66 	}
67 
68 	return fw_cap;
69 }
70 
71 /*
72  * Helper function to query gpu virtualizaiton capability
73  *
74  * @adev: amdgpu_device pointer
75  *
76  * Return true if gpu virtualization is supported or false if not
77  */
78 bool amdgpu_atomfirmware_gpu_virtualization_supported(struct amdgpu_device *adev)
79 {
80 	u32 fw_cap;
81 
82 	fw_cap = adev->mode_info.firmware_flags;
83 
84 	return (fw_cap & ATOM_FIRMWARE_CAP_GPU_VIRTUALIZATION) ? true : false;
85 }
86 
87 void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev)
88 {
89 	int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
90 						firmwareinfo);
91 	uint16_t data_offset;
92 
93 	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, NULL,
94 					  NULL, NULL, &data_offset)) {
95 		struct atom_firmware_info_v3_1 *firmware_info =
96 			(struct atom_firmware_info_v3_1 *)(adev->mode_info.atom_context->bios +
97 							   data_offset);
98 
99 		adev->bios_scratch_reg_offset =
100 			le32_to_cpu(firmware_info->bios_scratch_reg_startaddr);
101 	}
102 }
103 
104 int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev)
105 {
106 	struct atom_context *ctx = adev->mode_info.atom_context;
107 	int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
108 						vram_usagebyfirmware);
109 	struct vram_usagebyfirmware_v2_1 *firmware_usage;
110 	uint32_t start_addr, size;
111 	uint16_t data_offset;
112 	int usage_bytes = 0;
113 
114 	if (amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
115 		firmware_usage = (struct vram_usagebyfirmware_v2_1 *)(ctx->bios + data_offset);
116 		DRM_DEBUG("atom firmware requested %08x %dkb fw %dkb drv\n",
117 			  le32_to_cpu(firmware_usage->start_address_in_kb),
118 			  le16_to_cpu(firmware_usage->used_by_firmware_in_kb),
119 			  le16_to_cpu(firmware_usage->used_by_driver_in_kb));
120 
121 		start_addr = le32_to_cpu(firmware_usage->start_address_in_kb);
122 		size = le16_to_cpu(firmware_usage->used_by_firmware_in_kb);
123 
124 		if ((uint32_t)(start_addr & ATOM_VRAM_OPERATION_FLAGS_MASK) ==
125 			(uint32_t)(ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATION <<
126 			ATOM_VRAM_OPERATION_FLAGS_SHIFT)) {
127 			/* Firmware request VRAM reservation for SR-IOV */
128 			adev->mman.fw_vram_usage_start_offset = (start_addr &
129 				(~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
130 			adev->mman.fw_vram_usage_size = size << 10;
131 			/* Use the default scratch size */
132 			usage_bytes = 0;
133 		} else {
134 			usage_bytes = le16_to_cpu(firmware_usage->used_by_driver_in_kb) << 10;
135 		}
136 	}
137 	ctx->scratch_size_bytes = 0;
138 	if (usage_bytes == 0)
139 		usage_bytes = 20 * 1024;
140 	/* allocate some scratch memory */
141 	ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL);
142 	if (!ctx->scratch)
143 		return -ENOMEM;
144 	ctx->scratch_size_bytes = usage_bytes;
145 	return 0;
146 }
147 
148 union igp_info {
149 	struct atom_integrated_system_info_v1_11 v11;
150 	struct atom_integrated_system_info_v1_12 v12;
151 	struct atom_integrated_system_info_v2_1 v21;
152 };
153 
154 union umc_info {
155 	struct atom_umc_info_v3_1 v31;
156 	struct atom_umc_info_v3_2 v32;
157 	struct atom_umc_info_v3_3 v33;
158 };
159 
160 union vram_info {
161 	struct atom_vram_info_header_v2_3 v23;
162 	struct atom_vram_info_header_v2_4 v24;
163 	struct atom_vram_info_header_v2_5 v25;
164 	struct atom_vram_info_header_v2_6 v26;
165 };
166 
167 union vram_module {
168 	struct atom_vram_module_v9 v9;
169 	struct atom_vram_module_v10 v10;
170 	struct atom_vram_module_v11 v11;
171 };
172 
173 static int convert_atom_mem_type_to_vram_type(struct amdgpu_device *adev,
174 					      int atom_mem_type)
175 {
176 	int vram_type;
177 
178 	if (adev->flags & AMD_IS_APU) {
179 		switch (atom_mem_type) {
180 		case Ddr2MemType:
181 		case LpDdr2MemType:
182 			vram_type = AMDGPU_VRAM_TYPE_DDR2;
183 			break;
184 		case Ddr3MemType:
185 		case LpDdr3MemType:
186 			vram_type = AMDGPU_VRAM_TYPE_DDR3;
187 			break;
188 		case Ddr4MemType:
189 		case LpDdr4MemType:
190 			vram_type = AMDGPU_VRAM_TYPE_DDR4;
191 			break;
192 		case Ddr5MemType:
193 		case LpDdr5MemType:
194 			vram_type = AMDGPU_VRAM_TYPE_DDR5;
195 			break;
196 		default:
197 			vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
198 			break;
199 		}
200 	} else {
201 		switch (atom_mem_type) {
202 		case ATOM_DGPU_VRAM_TYPE_GDDR5:
203 			vram_type = AMDGPU_VRAM_TYPE_GDDR5;
204 			break;
205 		case ATOM_DGPU_VRAM_TYPE_HBM2:
206 		case ATOM_DGPU_VRAM_TYPE_HBM2E:
207 			vram_type = AMDGPU_VRAM_TYPE_HBM;
208 			break;
209 		case ATOM_DGPU_VRAM_TYPE_GDDR6:
210 			vram_type = AMDGPU_VRAM_TYPE_GDDR6;
211 			break;
212 		default:
213 			vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
214 			break;
215 		}
216 	}
217 
218 	return vram_type;
219 }
220 
221 
222 int
223 amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
224 				  int *vram_width, int *vram_type,
225 				  int *vram_vendor)
226 {
227 	struct amdgpu_mode_info *mode_info = &adev->mode_info;
228 	int index, i = 0;
229 	u16 data_offset, size;
230 	union igp_info *igp_info;
231 	union vram_info *vram_info;
232 	union vram_module *vram_module;
233 	u8 frev, crev;
234 	u8 mem_type;
235 	u8 mem_vendor;
236 	u32 mem_channel_number;
237 	u32 mem_channel_width;
238 	u32 module_id;
239 
240 	if (adev->flags & AMD_IS_APU)
241 		index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
242 						    integratedsysteminfo);
243 	else
244 		index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
245 						    vram_info);
246 
247 	if (amdgpu_atom_parse_data_header(mode_info->atom_context,
248 					  index, &size,
249 					  &frev, &crev, &data_offset)) {
250 		if (adev->flags & AMD_IS_APU) {
251 			igp_info = (union igp_info *)
252 				(mode_info->atom_context->bios + data_offset);
253 			switch (frev) {
254 			case 1:
255 				switch (crev) {
256 				case 11:
257 				case 12:
258 					mem_channel_number = igp_info->v11.umachannelnumber;
259 					if (!mem_channel_number)
260 						mem_channel_number = 1;
261 					/* channel width is 64 */
262 					if (vram_width)
263 						*vram_width = mem_channel_number * 64;
264 					mem_type = igp_info->v11.memorytype;
265 					if (vram_type)
266 						*vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
267 					break;
268 				default:
269 					return -EINVAL;
270 				}
271 				break;
272 			case 2:
273 				switch (crev) {
274 				case 1:
275 				case 2:
276 					mem_channel_number = igp_info->v21.umachannelnumber;
277 					if (!mem_channel_number)
278 						mem_channel_number = 1;
279 					/* channel width is 64 */
280 					if (vram_width)
281 						*vram_width = mem_channel_number * 64;
282 					mem_type = igp_info->v21.memorytype;
283 					if (vram_type)
284 						*vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
285 					break;
286 				default:
287 					return -EINVAL;
288 				}
289 				break;
290 			default:
291 				return -EINVAL;
292 			}
293 		} else {
294 			vram_info = (union vram_info *)
295 				(mode_info->atom_context->bios + data_offset);
296 			module_id = (RREG32(adev->bios_scratch_reg_offset + 4) & 0x00ff0000) >> 16;
297 			switch (crev) {
298 			case 3:
299 				if (module_id > vram_info->v23.vram_module_num)
300 					module_id = 0;
301 				vram_module = (union vram_module *)vram_info->v23.vram_module;
302 				while (i < module_id) {
303 					vram_module = (union vram_module *)
304 						((u8 *)vram_module + vram_module->v9.vram_module_size);
305 					i++;
306 				}
307 				mem_type = vram_module->v9.memory_type;
308 				if (vram_type)
309 					*vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
310 				mem_channel_number = vram_module->v9.channel_num;
311 				mem_channel_width = vram_module->v9.channel_width;
312 				if (vram_width)
313 					*vram_width = mem_channel_number * (1 << mem_channel_width);
314 				mem_vendor = (vram_module->v9.vender_rev_id) & 0xF;
315 				if (vram_vendor)
316 					*vram_vendor = mem_vendor;
317 				break;
318 			case 4:
319 				if (module_id > vram_info->v24.vram_module_num)
320 					module_id = 0;
321 				vram_module = (union vram_module *)vram_info->v24.vram_module;
322 				while (i < module_id) {
323 					vram_module = (union vram_module *)
324 						((u8 *)vram_module + vram_module->v10.vram_module_size);
325 					i++;
326 				}
327 				mem_type = vram_module->v10.memory_type;
328 				if (vram_type)
329 					*vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
330 				mem_channel_number = vram_module->v10.channel_num;
331 				mem_channel_width = vram_module->v10.channel_width;
332 				if (vram_width)
333 					*vram_width = mem_channel_number * (1 << mem_channel_width);
334 				mem_vendor = (vram_module->v10.vender_rev_id) & 0xF;
335 				if (vram_vendor)
336 					*vram_vendor = mem_vendor;
337 				break;
338 			case 5:
339 				if (module_id > vram_info->v25.vram_module_num)
340 					module_id = 0;
341 				vram_module = (union vram_module *)vram_info->v25.vram_module;
342 				while (i < module_id) {
343 					vram_module = (union vram_module *)
344 						((u8 *)vram_module + vram_module->v11.vram_module_size);
345 					i++;
346 				}
347 				mem_type = vram_module->v11.memory_type;
348 				if (vram_type)
349 					*vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
350 				mem_channel_number = vram_module->v11.channel_num;
351 				mem_channel_width = vram_module->v11.channel_width;
352 				if (vram_width)
353 					*vram_width = mem_channel_number * (1 << mem_channel_width);
354 				mem_vendor = (vram_module->v11.vender_rev_id) & 0xF;
355 				if (vram_vendor)
356 					*vram_vendor = mem_vendor;
357 				break;
358 			case 6:
359 				if (module_id > vram_info->v26.vram_module_num)
360 					module_id = 0;
361 				vram_module = (union vram_module *)vram_info->v26.vram_module;
362 				while (i < module_id) {
363 					vram_module = (union vram_module *)
364 						((u8 *)vram_module + vram_module->v9.vram_module_size);
365 					i++;
366 				}
367 				mem_type = vram_module->v9.memory_type;
368 				if (vram_type)
369 					*vram_type = convert_atom_mem_type_to_vram_type(adev, mem_type);
370 				mem_channel_number = vram_module->v9.channel_num;
371 				mem_channel_width = vram_module->v9.channel_width;
372 				if (vram_width)
373 					*vram_width = mem_channel_number * (1 << mem_channel_width);
374 				mem_vendor = (vram_module->v9.vender_rev_id) & 0xF;
375 				if (vram_vendor)
376 					*vram_vendor = mem_vendor;
377 				break;
378 			default:
379 				return -EINVAL;
380 			}
381 		}
382 
383 	}
384 
385 	return 0;
386 }
387 
388 /*
389  * Return true if vbios enabled ecc by default, if umc info table is available
390  * or false if ecc is not enabled or umc info table is not available
391  */
392 bool amdgpu_atomfirmware_mem_ecc_supported(struct amdgpu_device *adev)
393 {
394 	struct amdgpu_mode_info *mode_info = &adev->mode_info;
395 	int index;
396 	u16 data_offset, size;
397 	union umc_info *umc_info;
398 	u8 frev, crev;
399 	bool ecc_default_enabled = false;
400 	u8 umc_config;
401 	u32 umc_config1;
402 
403 	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
404 			umc_info);
405 
406 	if (amdgpu_atom_parse_data_header(mode_info->atom_context,
407 				index, &size, &frev, &crev, &data_offset)) {
408 		if (frev == 3) {
409 			umc_info = (union umc_info *)
410 				(mode_info->atom_context->bios + data_offset);
411 			switch (crev) {
412 			case 1:
413 				umc_config = le32_to_cpu(umc_info->v31.umc_config);
414 				ecc_default_enabled =
415 					(umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ? true : false;
416 				break;
417 			case 2:
418 				umc_config = le32_to_cpu(umc_info->v32.umc_config);
419 				ecc_default_enabled =
420 					(umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ? true : false;
421 				break;
422 			case 3:
423 				umc_config = le32_to_cpu(umc_info->v33.umc_config);
424 				umc_config1 = le32_to_cpu(umc_info->v33.umc_config1);
425 				ecc_default_enabled =
426 					((umc_config & UMC_CONFIG__DEFAULT_MEM_ECC_ENABLE) ||
427 					 (umc_config1 & UMC_CONFIG1__ENABLE_ECC_CAPABLE)) ? true : false;
428 				break;
429 			default:
430 				/* unsupported crev */
431 				return false;
432 			}
433 		}
434 	}
435 
436 	return ecc_default_enabled;
437 }
438 
439 /*
440  * Helper function to query sram ecc capablity
441  *
442  * @adev: amdgpu_device pointer
443  *
444  * Return true if vbios supports sram ecc or false if not
445  */
446 bool amdgpu_atomfirmware_sram_ecc_supported(struct amdgpu_device *adev)
447 {
448 	u32 fw_cap;
449 
450 	fw_cap = adev->mode_info.firmware_flags;
451 
452 	return (fw_cap & ATOM_FIRMWARE_CAP_SRAM_ECC) ? true : false;
453 }
454 
455 /*
456  * Helper function to query dynamic boot config capability
457  *
458  * @adev: amdgpu_device pointer
459  *
460  * Return true if vbios supports dynamic boot config or false if not
461  */
462 bool amdgpu_atomfirmware_dynamic_boot_config_supported(struct amdgpu_device *adev)
463 {
464 	u32 fw_cap;
465 
466 	fw_cap = adev->mode_info.firmware_flags;
467 
468 	return (fw_cap & ATOM_FIRMWARE_CAP_DYNAMIC_BOOT_CFG_ENABLE) ? true : false;
469 }
470 
471 union smu_info {
472 	struct atom_smu_info_v3_1 v31;
473 };
474 
475 int amdgpu_atomfirmware_get_clock_info(struct amdgpu_device *adev)
476 {
477 	struct amdgpu_mode_info *mode_info = &adev->mode_info;
478 	struct amdgpu_pll *spll = &adev->clock.spll;
479 	struct amdgpu_pll *mpll = &adev->clock.mpll;
480 	uint8_t frev, crev;
481 	uint16_t data_offset;
482 	int ret = -EINVAL, index;
483 
484 	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
485 					    firmwareinfo);
486 	if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
487 				   &frev, &crev, &data_offset)) {
488 		union firmware_info *firmware_info =
489 			(union firmware_info *)(mode_info->atom_context->bios +
490 						data_offset);
491 
492 		adev->clock.default_sclk =
493 			le32_to_cpu(firmware_info->v31.bootup_sclk_in10khz);
494 		adev->clock.default_mclk =
495 			le32_to_cpu(firmware_info->v31.bootup_mclk_in10khz);
496 
497 		adev->pm.current_sclk = adev->clock.default_sclk;
498 		adev->pm.current_mclk = adev->clock.default_mclk;
499 
500 		ret = 0;
501 	}
502 
503 	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
504 					    smu_info);
505 	if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
506 				   &frev, &crev, &data_offset)) {
507 		union smu_info *smu_info =
508 			(union smu_info *)(mode_info->atom_context->bios +
509 					   data_offset);
510 
511 		/* system clock */
512 		spll->reference_freq = le32_to_cpu(smu_info->v31.core_refclk_10khz);
513 
514 		spll->reference_div = 0;
515 		spll->min_post_div = 1;
516 		spll->max_post_div = 1;
517 		spll->min_ref_div = 2;
518 		spll->max_ref_div = 0xff;
519 		spll->min_feedback_div = 4;
520 		spll->max_feedback_div = 0xff;
521 		spll->best_vco = 0;
522 
523 		ret = 0;
524 	}
525 
526 	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
527 					    umc_info);
528 	if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
529 				   &frev, &crev, &data_offset)) {
530 		union umc_info *umc_info =
531 			(union umc_info *)(mode_info->atom_context->bios +
532 					   data_offset);
533 
534 		/* memory clock */
535 		mpll->reference_freq = le32_to_cpu(umc_info->v31.mem_refclk_10khz);
536 
537 		mpll->reference_div = 0;
538 		mpll->min_post_div = 1;
539 		mpll->max_post_div = 1;
540 		mpll->min_ref_div = 2;
541 		mpll->max_ref_div = 0xff;
542 		mpll->min_feedback_div = 4;
543 		mpll->max_feedback_div = 0xff;
544 		mpll->best_vco = 0;
545 
546 		ret = 0;
547 	}
548 
549 	/* if asic is Navi+, the rlc reference clock is used for system clock
550 	 * from vbios gfx_info table */
551 	if (adev->asic_type >= CHIP_NAVI10) {
552 		index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
553 						   gfx_info);
554 		if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
555 					  &frev, &crev, &data_offset)) {
556 			struct atom_gfx_info_v2_2 *gfx_info = (struct atom_gfx_info_v2_2*)
557 				(mode_info->atom_context->bios + data_offset);
558 			if ((frev == 2) && (crev >= 2))
559 				spll->reference_freq = le32_to_cpu(gfx_info->rlc_gpu_timer_refclk);
560 			ret = 0;
561 		}
562 	}
563 
564 	return ret;
565 }
566 
567 union gfx_info {
568 	struct atom_gfx_info_v2_4 v24;
569 	struct atom_gfx_info_v2_7 v27;
570 };
571 
572 int amdgpu_atomfirmware_get_gfx_info(struct amdgpu_device *adev)
573 {
574 	struct amdgpu_mode_info *mode_info = &adev->mode_info;
575 	int index;
576 	uint8_t frev, crev;
577 	uint16_t data_offset;
578 
579 	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
580 					    gfx_info);
581 	if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
582 				   &frev, &crev, &data_offset)) {
583 		union gfx_info *gfx_info = (union gfx_info *)
584 			(mode_info->atom_context->bios + data_offset);
585 		switch (crev) {
586 		case 4:
587 			adev->gfx.config.max_shader_engines = gfx_info->v24.max_shader_engines;
588 			adev->gfx.config.max_cu_per_sh = gfx_info->v24.max_cu_per_sh;
589 			adev->gfx.config.max_sh_per_se = gfx_info->v24.max_sh_per_se;
590 			adev->gfx.config.max_backends_per_se = gfx_info->v24.max_backends_per_se;
591 			adev->gfx.config.max_texture_channel_caches = gfx_info->v24.max_texture_channel_caches;
592 			adev->gfx.config.max_gprs = le16_to_cpu(gfx_info->v24.gc_num_gprs);
593 			adev->gfx.config.max_gs_threads = gfx_info->v24.gc_num_max_gs_thds;
594 			adev->gfx.config.gs_vgt_table_depth = gfx_info->v24.gc_gs_table_depth;
595 			adev->gfx.config.gs_prim_buffer_depth =
596 				le16_to_cpu(gfx_info->v24.gc_gsprim_buff_depth);
597 			adev->gfx.config.double_offchip_lds_buf =
598 				gfx_info->v24.gc_double_offchip_lds_buffer;
599 			adev->gfx.cu_info.wave_front_size = le16_to_cpu(gfx_info->v24.gc_wave_size);
600 			adev->gfx.cu_info.max_waves_per_simd = le16_to_cpu(gfx_info->v24.gc_max_waves_per_simd);
601 			adev->gfx.cu_info.max_scratch_slots_per_cu = gfx_info->v24.gc_max_scratch_slots_per_cu;
602 			adev->gfx.cu_info.lds_size = le16_to_cpu(gfx_info->v24.gc_lds_size);
603 			return 0;
604 		case 7:
605 			adev->gfx.config.max_shader_engines = gfx_info->v27.max_shader_engines;
606 			adev->gfx.config.max_cu_per_sh = gfx_info->v27.max_cu_per_sh;
607 			adev->gfx.config.max_sh_per_se = gfx_info->v27.max_sh_per_se;
608 			adev->gfx.config.max_backends_per_se = gfx_info->v27.max_backends_per_se;
609 			adev->gfx.config.max_texture_channel_caches = gfx_info->v27.max_texture_channel_caches;
610 			adev->gfx.config.max_gprs = le16_to_cpu(gfx_info->v27.gc_num_gprs);
611 			adev->gfx.config.max_gs_threads = gfx_info->v27.gc_num_max_gs_thds;
612 			adev->gfx.config.gs_vgt_table_depth = gfx_info->v27.gc_gs_table_depth;
613 			adev->gfx.config.gs_prim_buffer_depth = le16_to_cpu(gfx_info->v27.gc_gsprim_buff_depth);
614 			adev->gfx.config.double_offchip_lds_buf = gfx_info->v27.gc_double_offchip_lds_buffer;
615 			adev->gfx.cu_info.wave_front_size = le16_to_cpu(gfx_info->v27.gc_wave_size);
616 			adev->gfx.cu_info.max_waves_per_simd = le16_to_cpu(gfx_info->v27.gc_max_waves_per_simd);
617 			adev->gfx.cu_info.max_scratch_slots_per_cu = gfx_info->v27.gc_max_scratch_slots_per_cu;
618 			adev->gfx.cu_info.lds_size = le16_to_cpu(gfx_info->v27.gc_lds_size);
619 			return 0;
620 		default:
621 			return -EINVAL;
622 		}
623 
624 	}
625 	return -EINVAL;
626 }
627 
628 /*
629  * Helper function to query two stage mem training capability
630  *
631  * @adev: amdgpu_device pointer
632  *
633  * Return true if two stage mem training is supported or false if not
634  */
635 bool amdgpu_atomfirmware_mem_training_supported(struct amdgpu_device *adev)
636 {
637 	u32 fw_cap;
638 
639 	fw_cap = adev->mode_info.firmware_flags;
640 
641 	return (fw_cap & ATOM_FIRMWARE_CAP_ENABLE_2STAGE_BIST_TRAINING) ? true : false;
642 }
643 
644 int amdgpu_atomfirmware_get_fw_reserved_fb_size(struct amdgpu_device *adev)
645 {
646 	struct atom_context *ctx = adev->mode_info.atom_context;
647 	union firmware_info *firmware_info;
648 	int index;
649 	u16 data_offset, size;
650 	u8 frev, crev;
651 	int fw_reserved_fb_size;
652 
653 	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
654 			firmwareinfo);
655 
656 	if (!amdgpu_atom_parse_data_header(ctx, index, &size,
657 				&frev, &crev, &data_offset))
658 		/* fail to parse data_header */
659 		return 0;
660 
661 	firmware_info = (union firmware_info *)(ctx->bios + data_offset);
662 
663 	if (frev !=3)
664 		return -EINVAL;
665 
666 	switch (crev) {
667 	case 4:
668 		fw_reserved_fb_size =
669 			(firmware_info->v34.fw_reserved_size_in_kb << 10);
670 		break;
671 	default:
672 		fw_reserved_fb_size = 0;
673 		break;
674 	}
675 
676 	return fw_reserved_fb_size;
677 }
678