• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012-15 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  * Authors: AMD
23  *
24  */
25 
26 #include <linux/slab.h>
27 
28 #include "dm_services.h"
29 
30 #include "ObjectID.h"
31 #include "atomfirmware.h"
32 
33 #include "dc_bios_types.h"
34 #include "include/grph_object_ctrl_defs.h"
35 #include "include/bios_parser_interface.h"
36 #include "include/i2caux_interface.h"
37 #include "include/logger_interface.h"
38 
39 #include "command_table2.h"
40 
41 #include "bios_parser_helper.h"
42 #include "command_table_helper2.h"
43 #include "bios_parser2.h"
44 #include "bios_parser_types_internal2.h"
45 #include "bios_parser_interface.h"
46 
47 #include "bios_parser_common.h"
48 
49 /* Temporarily add in defines until ObjectID.h patch is updated in a few days */
50 #ifndef GENERIC_OBJECT_ID_BRACKET_LAYOUT
51 #define GENERIC_OBJECT_ID_BRACKET_LAYOUT          0x05
52 #endif /* GENERIC_OBJECT_ID_BRACKET_LAYOUT */
53 
54 #ifndef GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID1
55 #define GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID1	\
56 	(GRAPH_OBJECT_TYPE_GENERIC << OBJECT_TYPE_SHIFT |\
57 	GRAPH_OBJECT_ENUM_ID1 << ENUM_ID_SHIFT |\
58 	GENERIC_OBJECT_ID_BRACKET_LAYOUT << OBJECT_ID_SHIFT)
59 #endif /* GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID1 */
60 
61 #ifndef GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID2
62 #define GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID2	\
63 	(GRAPH_OBJECT_TYPE_GENERIC << OBJECT_TYPE_SHIFT |\
64 	GRAPH_OBJECT_ENUM_ID2 << ENUM_ID_SHIFT |\
65 	GENERIC_OBJECT_ID_BRACKET_LAYOUT << OBJECT_ID_SHIFT)
66 #endif /* GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID2 */
67 
68 #define DC_LOGGER \
69 	bp->base.ctx->logger
70 
71 #define LAST_RECORD_TYPE 0xff
72 #define SMU9_SYSPLL0_ID  0
73 
74 struct i2c_id_config_access {
75 	uint8_t bfI2C_LineMux:4;
76 	uint8_t bfHW_EngineID:3;
77 	uint8_t bfHW_Capable:1;
78 	uint8_t ucAccess;
79 };
80 
81 static enum bp_result get_gpio_i2c_info(struct bios_parser *bp,
82 	struct atom_i2c_record *record,
83 	struct graphics_object_i2c_info *info);
84 
85 static enum bp_result bios_parser_get_firmware_info(
86 	struct dc_bios *dcb,
87 	struct dc_firmware_info *info);
88 
89 static enum bp_result bios_parser_get_encoder_cap_info(
90 	struct dc_bios *dcb,
91 	struct graphics_object_id object_id,
92 	struct bp_encoder_cap_info *info);
93 
94 static enum bp_result get_firmware_info_v3_1(
95 	struct bios_parser *bp,
96 	struct dc_firmware_info *info);
97 
98 static enum bp_result get_firmware_info_v3_2(
99 	struct bios_parser *bp,
100 	struct dc_firmware_info *info);
101 
102 static struct atom_hpd_int_record *get_hpd_record(struct bios_parser *bp,
103 		struct atom_display_object_path_v2 *object);
104 
105 static struct atom_encoder_caps_record *get_encoder_cap_record(
106 	struct bios_parser *bp,
107 	struct atom_display_object_path_v2 *object);
108 
109 #define BIOS_IMAGE_SIZE_OFFSET 2
110 #define BIOS_IMAGE_SIZE_UNIT 512
111 
112 #define DATA_TABLES(table) (bp->master_data_tbl->listOfdatatables.table)
113 
bios_parser2_destruct(struct bios_parser * bp)114 static void bios_parser2_destruct(struct bios_parser *bp)
115 {
116 	kfree(bp->base.bios_local_image);
117 	kfree(bp->base.integrated_info);
118 }
119 
firmware_parser_destroy(struct dc_bios ** dcb)120 static void firmware_parser_destroy(struct dc_bios **dcb)
121 {
122 	struct bios_parser *bp = BP_FROM_DCB(*dcb);
123 
124 	if (!bp) {
125 		BREAK_TO_DEBUGGER();
126 		return;
127 	}
128 
129 	bios_parser2_destruct(bp);
130 
131 	kfree(bp);
132 	*dcb = NULL;
133 }
134 
get_atom_data_table_revision(struct atom_common_table_header * atom_data_tbl,struct atom_data_revision * tbl_revision)135 static void get_atom_data_table_revision(
136 	struct atom_common_table_header *atom_data_tbl,
137 	struct atom_data_revision *tbl_revision)
138 {
139 	if (!tbl_revision)
140 		return;
141 
142 	/* initialize the revision to 0 which is invalid revision */
143 	tbl_revision->major = 0;
144 	tbl_revision->minor = 0;
145 
146 	if (!atom_data_tbl)
147 		return;
148 
149 	tbl_revision->major =
150 			(uint32_t) atom_data_tbl->format_revision & 0x3f;
151 	tbl_revision->minor =
152 			(uint32_t) atom_data_tbl->content_revision & 0x3f;
153 }
154 
155 /* BIOS oject table displaypath is per connector.
156  * There is extra path not for connector. BIOS fill its encoderid as 0
157  */
bios_parser_get_connectors_number(struct dc_bios * dcb)158 static uint8_t bios_parser_get_connectors_number(struct dc_bios *dcb)
159 {
160 	struct bios_parser *bp = BP_FROM_DCB(dcb);
161 	unsigned int count = 0;
162 	unsigned int i;
163 
164 	for (i = 0; i < bp->object_info_tbl.v1_4->number_of_path; i++) {
165 		if (bp->object_info_tbl.v1_4->display_path[i].encoderobjid != 0)
166 			count++;
167 	}
168 	return count;
169 }
170 
bios_parser_get_connector_id(struct dc_bios * dcb,uint8_t i)171 static struct graphics_object_id bios_parser_get_connector_id(
172 	struct dc_bios *dcb,
173 	uint8_t i)
174 {
175 	struct bios_parser *bp = BP_FROM_DCB(dcb);
176 	struct graphics_object_id object_id = dal_graphics_object_id_init(
177 		0, ENUM_ID_UNKNOWN, OBJECT_TYPE_UNKNOWN);
178 	struct object_info_table *tbl = &bp->object_info_tbl;
179 	struct display_object_info_table_v1_4 *v1_4 = tbl->v1_4;
180 
181 	if (v1_4->number_of_path > i) {
182 		/* If display_objid is generic object id,  the encoderObj
183 		 * /extencoderobjId should be 0
184 		 */
185 		if (v1_4->display_path[i].encoderobjid != 0 &&
186 				v1_4->display_path[i].display_objid != 0)
187 			object_id = object_id_from_bios_object_id(
188 					v1_4->display_path[i].display_objid);
189 	}
190 
191 	return object_id;
192 }
193 
bios_parser_get_src_obj(struct dc_bios * dcb,struct graphics_object_id object_id,uint32_t index,struct graphics_object_id * src_object_id)194 static enum bp_result bios_parser_get_src_obj(struct dc_bios *dcb,
195 	struct graphics_object_id object_id, uint32_t index,
196 	struct graphics_object_id *src_object_id)
197 {
198 	struct bios_parser *bp = BP_FROM_DCB(dcb);
199 	unsigned int i;
200 	enum bp_result  bp_result = BP_RESULT_BADINPUT;
201 	struct graphics_object_id obj_id = {0};
202 	struct object_info_table *tbl = &bp->object_info_tbl;
203 
204 	if (!src_object_id)
205 		return bp_result;
206 
207 	switch (object_id.type) {
208 	/* Encoder's Source is GPU.  BIOS does not provide GPU, since all
209 	 * displaypaths point to same GPU (0x1100).  Hardcode GPU object type
210 	 */
211 	case OBJECT_TYPE_ENCODER:
212 		/* TODO: since num of src must be less than 2.
213 		 * If found in for loop, should break.
214 		 * DAL2 implementation may be changed too
215 		 */
216 		for (i = 0; i < tbl->v1_4->number_of_path; i++) {
217 			obj_id = object_id_from_bios_object_id(
218 			tbl->v1_4->display_path[i].encoderobjid);
219 			if (object_id.type == obj_id.type &&
220 					object_id.id == obj_id.id &&
221 						object_id.enum_id ==
222 							obj_id.enum_id) {
223 				*src_object_id =
224 				object_id_from_bios_object_id(0x1100);
225 				/* break; */
226 			}
227 		}
228 		bp_result = BP_RESULT_OK;
229 		break;
230 	case OBJECT_TYPE_CONNECTOR:
231 		for (i = 0; i < tbl->v1_4->number_of_path; i++) {
232 			obj_id = object_id_from_bios_object_id(
233 				tbl->v1_4->display_path[i].display_objid);
234 
235 			if (object_id.type == obj_id.type &&
236 				object_id.id == obj_id.id &&
237 					object_id.enum_id == obj_id.enum_id) {
238 				*src_object_id =
239 				object_id_from_bios_object_id(
240 				tbl->v1_4->display_path[i].encoderobjid);
241 				/* break; */
242 			}
243 		}
244 		bp_result = BP_RESULT_OK;
245 		break;
246 	default:
247 		break;
248 	}
249 
250 	return bp_result;
251 }
252 
253 /* from graphics_object_id, find display path which includes the object_id */
get_bios_object(struct bios_parser * bp,struct graphics_object_id id)254 static struct atom_display_object_path_v2 *get_bios_object(
255 		struct bios_parser *bp,
256 		struct graphics_object_id id)
257 {
258 	unsigned int i;
259 	struct graphics_object_id obj_id = {0};
260 
261 	switch (id.type) {
262 	case OBJECT_TYPE_ENCODER:
263 		for (i = 0; i < bp->object_info_tbl.v1_4->number_of_path; i++) {
264 			obj_id = object_id_from_bios_object_id(
265 					bp->object_info_tbl.v1_4->display_path[i].encoderobjid);
266 			if (id.type == obj_id.type && id.id == obj_id.id
267 					&& id.enum_id == obj_id.enum_id)
268 				return &bp->object_info_tbl.v1_4->display_path[i];
269 		}
270 		fallthrough;
271 	case OBJECT_TYPE_CONNECTOR:
272 	case OBJECT_TYPE_GENERIC:
273 		/* Both Generic and Connector Object ID
274 		 * will be stored on display_objid
275 		 */
276 		for (i = 0; i < bp->object_info_tbl.v1_4->number_of_path; i++) {
277 			obj_id = object_id_from_bios_object_id(
278 					bp->object_info_tbl.v1_4->display_path[i].display_objid);
279 			if (id.type == obj_id.type && id.id == obj_id.id
280 					&& id.enum_id == obj_id.enum_id)
281 				return &bp->object_info_tbl.v1_4->display_path[i];
282 		}
283 		fallthrough;
284 	default:
285 		return NULL;
286 	}
287 }
288 
bios_parser_get_i2c_info(struct dc_bios * dcb,struct graphics_object_id id,struct graphics_object_i2c_info * info)289 static enum bp_result bios_parser_get_i2c_info(struct dc_bios *dcb,
290 	struct graphics_object_id id,
291 	struct graphics_object_i2c_info *info)
292 {
293 	uint32_t offset;
294 	struct atom_display_object_path_v2 *object;
295 	struct atom_common_record_header *header;
296 	struct atom_i2c_record *record;
297 	struct atom_i2c_record dummy_record = {0};
298 	struct bios_parser *bp = BP_FROM_DCB(dcb);
299 
300 	if (!info)
301 		return BP_RESULT_BADINPUT;
302 
303 	if (id.type == OBJECT_TYPE_GENERIC) {
304 		dummy_record.i2c_id = id.id;
305 
306 		if (get_gpio_i2c_info(bp, &dummy_record, info) == BP_RESULT_OK)
307 			return BP_RESULT_OK;
308 		else
309 			return BP_RESULT_NORECORD;
310 	}
311 
312 	object = get_bios_object(bp, id);
313 
314 	if (!object)
315 		return BP_RESULT_BADINPUT;
316 
317 	offset = object->disp_recordoffset + bp->object_info_tbl_offset;
318 
319 	for (;;) {
320 		header = GET_IMAGE(struct atom_common_record_header, offset);
321 
322 		if (!header)
323 			return BP_RESULT_BADBIOSTABLE;
324 
325 		if (header->record_type == LAST_RECORD_TYPE ||
326 			!header->record_size)
327 			break;
328 
329 		if (header->record_type == ATOM_I2C_RECORD_TYPE
330 			&& sizeof(struct atom_i2c_record) <=
331 							header->record_size) {
332 			/* get the I2C info */
333 			record = (struct atom_i2c_record *) header;
334 
335 			if (get_gpio_i2c_info(bp, record, info) ==
336 								BP_RESULT_OK)
337 				return BP_RESULT_OK;
338 		}
339 
340 		offset += header->record_size;
341 	}
342 
343 	return BP_RESULT_NORECORD;
344 }
345 
get_gpio_i2c_info(struct bios_parser * bp,struct atom_i2c_record * record,struct graphics_object_i2c_info * info)346 static enum bp_result get_gpio_i2c_info(
347 	struct bios_parser *bp,
348 	struct atom_i2c_record *record,
349 	struct graphics_object_i2c_info *info)
350 {
351 	struct atom_gpio_pin_lut_v2_1 *header;
352 	uint32_t count = 0;
353 	unsigned int table_index = 0;
354 	bool find_valid = false;
355 	struct atom_gpio_pin_assignment *pin;
356 
357 	if (!info)
358 		return BP_RESULT_BADINPUT;
359 
360 	/* get the GPIO_I2C info */
361 	if (!DATA_TABLES(gpio_pin_lut))
362 		return BP_RESULT_BADBIOSTABLE;
363 
364 	header = GET_IMAGE(struct atom_gpio_pin_lut_v2_1,
365 					DATA_TABLES(gpio_pin_lut));
366 	if (!header)
367 		return BP_RESULT_BADBIOSTABLE;
368 
369 	if (sizeof(struct atom_common_table_header) +
370 			sizeof(struct atom_gpio_pin_assignment)	>
371 			le16_to_cpu(header->table_header.structuresize))
372 		return BP_RESULT_BADBIOSTABLE;
373 
374 	/* TODO: is version change? */
375 	if (header->table_header.content_revision != 1)
376 		return BP_RESULT_UNSUPPORTED;
377 
378 	/* get data count */
379 	count = (le16_to_cpu(header->table_header.structuresize)
380 			- sizeof(struct atom_common_table_header))
381 				/ sizeof(struct atom_gpio_pin_assignment);
382 
383 	pin = (struct atom_gpio_pin_assignment *) header->gpio_pin;
384 
385 	for (table_index = 0; table_index < count; table_index++) {
386 		if (((record->i2c_id & I2C_HW_CAP) 				== (pin->gpio_id & I2C_HW_CAP)) &&
387 		    ((record->i2c_id & I2C_HW_ENGINE_ID_MASK)	== (pin->gpio_id & I2C_HW_ENGINE_ID_MASK)) &&
388 		    ((record->i2c_id & I2C_HW_LANE_MUX) 		== (pin->gpio_id & I2C_HW_LANE_MUX))) {
389 			/* still valid */
390 			find_valid = true;
391 			break;
392 		}
393 		pin = (struct atom_gpio_pin_assignment *)((uint8_t *)pin + sizeof(struct atom_gpio_pin_assignment));
394 	}
395 
396 	/* If we don't find the entry that we are looking for then
397 	 *  we will return BP_Result_BadBiosTable.
398 	 */
399 	if (find_valid == false)
400 		return BP_RESULT_BADBIOSTABLE;
401 
402 	/* get the GPIO_I2C_INFO */
403 	info->i2c_hw_assist = (record->i2c_id & I2C_HW_CAP) ? true : false;
404 	info->i2c_line = record->i2c_id & I2C_HW_LANE_MUX;
405 	info->i2c_engine_id = (record->i2c_id & I2C_HW_ENGINE_ID_MASK) >> 4;
406 	info->i2c_slave_address = record->i2c_slave_addr;
407 
408 	/* TODO: check how to get register offset for en, Y, etc. */
409 	info->gpio_info.clk_a_register_index =
410 			le16_to_cpu(
411 			header->gpio_pin[table_index].data_a_reg_index);
412 	info->gpio_info.clk_a_shift =
413 			header->gpio_pin[table_index].gpio_bitshift;
414 
415 	return BP_RESULT_OK;
416 }
417 
bios_parser_get_hpd_info(struct dc_bios * dcb,struct graphics_object_id id,struct graphics_object_hpd_info * info)418 static enum bp_result bios_parser_get_hpd_info(
419 	struct dc_bios *dcb,
420 	struct graphics_object_id id,
421 	struct graphics_object_hpd_info *info)
422 {
423 	struct bios_parser *bp = BP_FROM_DCB(dcb);
424 	struct atom_display_object_path_v2 *object;
425 	struct atom_hpd_int_record *record = NULL;
426 
427 	if (!info)
428 		return BP_RESULT_BADINPUT;
429 
430 	object = get_bios_object(bp, id);
431 
432 	if (!object)
433 		return BP_RESULT_BADINPUT;
434 
435 	record = get_hpd_record(bp, object);
436 
437 	if (record != NULL) {
438 		info->hpd_int_gpio_uid = record->pin_id;
439 		info->hpd_active = record->plugin_pin_state;
440 		return BP_RESULT_OK;
441 	}
442 
443 	return BP_RESULT_NORECORD;
444 }
445 
get_hpd_record(struct bios_parser * bp,struct atom_display_object_path_v2 * object)446 static struct atom_hpd_int_record *get_hpd_record(
447 	struct bios_parser *bp,
448 	struct atom_display_object_path_v2 *object)
449 {
450 	struct atom_common_record_header *header;
451 	uint32_t offset;
452 
453 	if (!object) {
454 		BREAK_TO_DEBUGGER(); /* Invalid object */
455 		return NULL;
456 	}
457 
458 	offset = le16_to_cpu(object->disp_recordoffset)
459 			+ bp->object_info_tbl_offset;
460 
461 	for (;;) {
462 		header = GET_IMAGE(struct atom_common_record_header, offset);
463 
464 		if (!header)
465 			return NULL;
466 
467 		if (header->record_type == LAST_RECORD_TYPE ||
468 			!header->record_size)
469 			break;
470 
471 		if (header->record_type == ATOM_HPD_INT_RECORD_TYPE
472 			&& sizeof(struct atom_hpd_int_record) <=
473 							header->record_size)
474 			return (struct atom_hpd_int_record *) header;
475 
476 		offset += header->record_size;
477 	}
478 
479 	return NULL;
480 }
481 
482 /**
483  * bios_parser_get_gpio_pin_info
484  * Get GpioPin information of input gpio id
485  *
486  * @param gpio_id, GPIO ID
487  * @param info, GpioPin information structure
488  * @return Bios parser result code
489  * @note
490  *  to get the GPIO PIN INFO, we need:
491  *  1. get the GPIO_ID from other object table, see GetHPDInfo()
492  *  2. in DATA_TABLE.GPIO_Pin_LUT, search all records,
493  *	to get the registerA  offset/mask
494  */
bios_parser_get_gpio_pin_info(struct dc_bios * dcb,uint32_t gpio_id,struct gpio_pin_info * info)495 static enum bp_result bios_parser_get_gpio_pin_info(
496 	struct dc_bios *dcb,
497 	uint32_t gpio_id,
498 	struct gpio_pin_info *info)
499 {
500 	struct bios_parser *bp = BP_FROM_DCB(dcb);
501 	struct atom_gpio_pin_lut_v2_1 *header;
502 	uint32_t count = 0;
503 	uint32_t i = 0;
504 
505 	if (!DATA_TABLES(gpio_pin_lut))
506 		return BP_RESULT_BADBIOSTABLE;
507 
508 	header = GET_IMAGE(struct atom_gpio_pin_lut_v2_1,
509 						DATA_TABLES(gpio_pin_lut));
510 	if (!header)
511 		return BP_RESULT_BADBIOSTABLE;
512 
513 	if (sizeof(struct atom_common_table_header) +
514 			sizeof(struct atom_gpio_pin_assignment)
515 			> le16_to_cpu(header->table_header.structuresize))
516 		return BP_RESULT_BADBIOSTABLE;
517 
518 	if (header->table_header.content_revision != 1)
519 		return BP_RESULT_UNSUPPORTED;
520 
521 	/* Temporary hard code gpio pin info */
522 #if defined(FOR_SIMNOW_BOOT)
523 	{
524 		struct  atom_gpio_pin_assignment  gpio_pin[8] = {
525 				{0x5db5, 0, 0, 1, 0},
526 				{0x5db5, 8, 8, 2, 0},
527 				{0x5db5, 0x10, 0x10, 3, 0},
528 				{0x5db5, 0x18, 0x14, 4, 0},
529 				{0x5db5, 0x1A, 0x18, 5, 0},
530 				{0x5db5, 0x1C, 0x1C, 6, 0},
531 		};
532 
533 		count = 6;
534 		memmove(header->gpio_pin, gpio_pin, sizeof(gpio_pin));
535 	}
536 #else
537 	count = (le16_to_cpu(header->table_header.structuresize)
538 			- sizeof(struct atom_common_table_header))
539 				/ sizeof(struct atom_gpio_pin_assignment);
540 #endif
541 	for (i = 0; i < count; ++i) {
542 		if (header->gpio_pin[i].gpio_id != gpio_id)
543 			continue;
544 
545 		info->offset =
546 			(uint32_t) le16_to_cpu(
547 					header->gpio_pin[i].data_a_reg_index);
548 		info->offset_y = info->offset + 2;
549 		info->offset_en = info->offset + 1;
550 		info->offset_mask = info->offset - 1;
551 
552 		info->mask = (uint32_t) (1 <<
553 			header->gpio_pin[i].gpio_bitshift);
554 		info->mask_y = info->mask + 2;
555 		info->mask_en = info->mask + 1;
556 		info->mask_mask = info->mask - 1;
557 
558 		return BP_RESULT_OK;
559 	}
560 
561 	return BP_RESULT_NORECORD;
562 }
563 
device_type_from_device_id(uint16_t device_id)564 static struct device_id device_type_from_device_id(uint16_t device_id)
565 {
566 
567 	struct device_id result_device_id;
568 
569 	result_device_id.raw_device_tag = device_id;
570 
571 	switch (device_id) {
572 	case ATOM_DISPLAY_LCD1_SUPPORT:
573 		result_device_id.device_type = DEVICE_TYPE_LCD;
574 		result_device_id.enum_id = 1;
575 		break;
576 
577 	case ATOM_DISPLAY_DFP1_SUPPORT:
578 		result_device_id.device_type = DEVICE_TYPE_DFP;
579 		result_device_id.enum_id = 1;
580 		break;
581 
582 	case ATOM_DISPLAY_DFP2_SUPPORT:
583 		result_device_id.device_type = DEVICE_TYPE_DFP;
584 		result_device_id.enum_id = 2;
585 		break;
586 
587 	case ATOM_DISPLAY_DFP3_SUPPORT:
588 		result_device_id.device_type = DEVICE_TYPE_DFP;
589 		result_device_id.enum_id = 3;
590 		break;
591 
592 	case ATOM_DISPLAY_DFP4_SUPPORT:
593 		result_device_id.device_type = DEVICE_TYPE_DFP;
594 		result_device_id.enum_id = 4;
595 		break;
596 
597 	case ATOM_DISPLAY_DFP5_SUPPORT:
598 		result_device_id.device_type = DEVICE_TYPE_DFP;
599 		result_device_id.enum_id = 5;
600 		break;
601 
602 	case ATOM_DISPLAY_DFP6_SUPPORT:
603 		result_device_id.device_type = DEVICE_TYPE_DFP;
604 		result_device_id.enum_id = 6;
605 		break;
606 
607 	default:
608 		BREAK_TO_DEBUGGER(); /* Invalid device Id */
609 		result_device_id.device_type = DEVICE_TYPE_UNKNOWN;
610 		result_device_id.enum_id = 0;
611 	}
612 	return result_device_id;
613 }
614 
bios_parser_get_device_tag(struct dc_bios * dcb,struct graphics_object_id connector_object_id,uint32_t device_tag_index,struct connector_device_tag_info * info)615 static enum bp_result bios_parser_get_device_tag(
616 	struct dc_bios *dcb,
617 	struct graphics_object_id connector_object_id,
618 	uint32_t device_tag_index,
619 	struct connector_device_tag_info *info)
620 {
621 	struct bios_parser *bp = BP_FROM_DCB(dcb);
622 	struct atom_display_object_path_v2 *object;
623 
624 	if (!info)
625 		return BP_RESULT_BADINPUT;
626 
627 	/* getBiosObject will return MXM object */
628 	object = get_bios_object(bp, connector_object_id);
629 
630 	if (!object) {
631 		BREAK_TO_DEBUGGER(); /* Invalid object id */
632 		return BP_RESULT_BADINPUT;
633 	}
634 
635 	info->acpi_device = 0; /* BIOS no longer provides this */
636 	info->dev_id = device_type_from_device_id(object->device_tag);
637 
638 	return BP_RESULT_OK;
639 }
640 
get_ss_info_v4_1(struct bios_parser * bp,uint32_t id,uint32_t index,struct spread_spectrum_info * ss_info)641 static enum bp_result get_ss_info_v4_1(
642 	struct bios_parser *bp,
643 	uint32_t id,
644 	uint32_t index,
645 	struct spread_spectrum_info *ss_info)
646 {
647 	enum bp_result result = BP_RESULT_OK;
648 	struct atom_display_controller_info_v4_1 *disp_cntl_tbl = NULL;
649 	struct atom_smu_info_v3_3 *smu_info = NULL;
650 
651 	if (!ss_info)
652 		return BP_RESULT_BADINPUT;
653 
654 	if (!DATA_TABLES(dce_info))
655 		return BP_RESULT_BADBIOSTABLE;
656 
657 	disp_cntl_tbl =  GET_IMAGE(struct atom_display_controller_info_v4_1,
658 							DATA_TABLES(dce_info));
659 	if (!disp_cntl_tbl)
660 		return BP_RESULT_BADBIOSTABLE;
661 
662 
663 	ss_info->type.STEP_AND_DELAY_INFO = false;
664 	ss_info->spread_percentage_divider = 1000;
665 	/* BIOS no longer uses target clock.  Always enable for now */
666 	ss_info->target_clock_range = 0xffffffff;
667 
668 	switch (id) {
669 	case AS_SIGNAL_TYPE_DVI:
670 		ss_info->spread_spectrum_percentage =
671 				disp_cntl_tbl->dvi_ss_percentage;
672 		ss_info->spread_spectrum_range =
673 				disp_cntl_tbl->dvi_ss_rate_10hz * 10;
674 		if (disp_cntl_tbl->dvi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
675 			ss_info->type.CENTER_MODE = true;
676 		break;
677 	case AS_SIGNAL_TYPE_HDMI:
678 		ss_info->spread_spectrum_percentage =
679 				disp_cntl_tbl->hdmi_ss_percentage;
680 		ss_info->spread_spectrum_range =
681 				disp_cntl_tbl->hdmi_ss_rate_10hz * 10;
682 		if (disp_cntl_tbl->hdmi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
683 			ss_info->type.CENTER_MODE = true;
684 		break;
685 	/* TODO LVDS not support anymore? */
686 	case AS_SIGNAL_TYPE_DISPLAY_PORT:
687 		ss_info->spread_spectrum_percentage =
688 				disp_cntl_tbl->dp_ss_percentage;
689 		ss_info->spread_spectrum_range =
690 				disp_cntl_tbl->dp_ss_rate_10hz * 10;
691 		if (disp_cntl_tbl->dp_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
692 			ss_info->type.CENTER_MODE = true;
693 		break;
694 	case AS_SIGNAL_TYPE_GPU_PLL:
695 		/* atom_firmware: DAL only get data from dce_info table.
696 		 * if data within smu_info is needed for DAL, VBIOS should
697 		 * copy it into dce_info
698 		 */
699 		result = BP_RESULT_UNSUPPORTED;
700 		break;
701 	case AS_SIGNAL_TYPE_XGMI:
702 		smu_info =  GET_IMAGE(struct atom_smu_info_v3_3,
703 				      DATA_TABLES(smu_info));
704 		if (!smu_info)
705 			return BP_RESULT_BADBIOSTABLE;
706 
707 		ss_info->spread_spectrum_percentage =
708 				smu_info->waflclk_ss_percentage;
709 		ss_info->spread_spectrum_range =
710 				smu_info->gpuclk_ss_rate_10hz * 10;
711 		if (smu_info->waflclk_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
712 			ss_info->type.CENTER_MODE = true;
713 		break;
714 	default:
715 		result = BP_RESULT_UNSUPPORTED;
716 	}
717 
718 	return result;
719 }
720 
get_ss_info_v4_2(struct bios_parser * bp,uint32_t id,uint32_t index,struct spread_spectrum_info * ss_info)721 static enum bp_result get_ss_info_v4_2(
722 	struct bios_parser *bp,
723 	uint32_t id,
724 	uint32_t index,
725 	struct spread_spectrum_info *ss_info)
726 {
727 	enum bp_result result = BP_RESULT_OK;
728 	struct atom_display_controller_info_v4_2 *disp_cntl_tbl = NULL;
729 	struct atom_smu_info_v3_1 *smu_info = NULL;
730 
731 	if (!ss_info)
732 		return BP_RESULT_BADINPUT;
733 
734 	if (!DATA_TABLES(dce_info))
735 		return BP_RESULT_BADBIOSTABLE;
736 
737 	if (!DATA_TABLES(smu_info))
738 		return BP_RESULT_BADBIOSTABLE;
739 
740 	disp_cntl_tbl =  GET_IMAGE(struct atom_display_controller_info_v4_2,
741 							DATA_TABLES(dce_info));
742 	if (!disp_cntl_tbl)
743 		return BP_RESULT_BADBIOSTABLE;
744 
745 	smu_info =  GET_IMAGE(struct atom_smu_info_v3_1, DATA_TABLES(smu_info));
746 	if (!smu_info)
747 		return BP_RESULT_BADBIOSTABLE;
748 
749 	ss_info->type.STEP_AND_DELAY_INFO = false;
750 	ss_info->spread_percentage_divider = 1000;
751 	/* BIOS no longer uses target clock.  Always enable for now */
752 	ss_info->target_clock_range = 0xffffffff;
753 
754 	switch (id) {
755 	case AS_SIGNAL_TYPE_DVI:
756 		ss_info->spread_spectrum_percentage =
757 				disp_cntl_tbl->dvi_ss_percentage;
758 		ss_info->spread_spectrum_range =
759 				disp_cntl_tbl->dvi_ss_rate_10hz * 10;
760 		if (disp_cntl_tbl->dvi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
761 			ss_info->type.CENTER_MODE = true;
762 		break;
763 	case AS_SIGNAL_TYPE_HDMI:
764 		ss_info->spread_spectrum_percentage =
765 				disp_cntl_tbl->hdmi_ss_percentage;
766 		ss_info->spread_spectrum_range =
767 				disp_cntl_tbl->hdmi_ss_rate_10hz * 10;
768 		if (disp_cntl_tbl->hdmi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
769 			ss_info->type.CENTER_MODE = true;
770 		break;
771 	/* TODO LVDS not support anymore? */
772 	case AS_SIGNAL_TYPE_DISPLAY_PORT:
773 		ss_info->spread_spectrum_percentage =
774 				smu_info->gpuclk_ss_percentage;
775 		ss_info->spread_spectrum_range =
776 				smu_info->gpuclk_ss_rate_10hz * 10;
777 		if (smu_info->gpuclk_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
778 			ss_info->type.CENTER_MODE = true;
779 		break;
780 	case AS_SIGNAL_TYPE_GPU_PLL:
781 		/* atom_firmware: DAL only get data from dce_info table.
782 		 * if data within smu_info is needed for DAL, VBIOS should
783 		 * copy it into dce_info
784 		 */
785 		result = BP_RESULT_UNSUPPORTED;
786 		break;
787 	default:
788 		result = BP_RESULT_UNSUPPORTED;
789 	}
790 
791 	return result;
792 }
793 
794 /**
795  * bios_parser_get_spread_spectrum_info
796  * Get spread spectrum information from the ASIC_InternalSS_Info(ver 2.1 or
797  * ver 3.1) or SS_Info table from the VBIOS. Currently ASIC_InternalSS_Info
798  * ver 2.1 can co-exist with SS_Info table. Expect ASIC_InternalSS_Info
799  * ver 3.1,
800  * there is only one entry for each signal /ss id.  However, there is
801  * no planning of supporting multiple spread Sprectum entry for EverGreen
802  * @param [in] this
803  * @param [in] signal, ASSignalType to be converted to info index
804  * @param [in] index, number of entries that match the converted info index
805  * @param [out] ss_info, sprectrum information structure,
806  * @return Bios parser result code
807  */
bios_parser_get_spread_spectrum_info(struct dc_bios * dcb,enum as_signal_type signal,uint32_t index,struct spread_spectrum_info * ss_info)808 static enum bp_result bios_parser_get_spread_spectrum_info(
809 	struct dc_bios *dcb,
810 	enum as_signal_type signal,
811 	uint32_t index,
812 	struct spread_spectrum_info *ss_info)
813 {
814 	struct bios_parser *bp = BP_FROM_DCB(dcb);
815 	enum bp_result result = BP_RESULT_UNSUPPORTED;
816 	struct atom_common_table_header *header;
817 	struct atom_data_revision tbl_revision;
818 
819 	if (!ss_info) /* check for bad input */
820 		return BP_RESULT_BADINPUT;
821 
822 	if (!DATA_TABLES(dce_info))
823 		return BP_RESULT_UNSUPPORTED;
824 
825 	header = GET_IMAGE(struct atom_common_table_header,
826 						DATA_TABLES(dce_info));
827 	get_atom_data_table_revision(header, &tbl_revision);
828 
829 	switch (tbl_revision.major) {
830 	case 4:
831 		switch (tbl_revision.minor) {
832 		case 1:
833 			return get_ss_info_v4_1(bp, signal, index, ss_info);
834 		case 2:
835 		case 3:
836 			return get_ss_info_v4_2(bp, signal, index, ss_info);
837 		default:
838 			break;
839 		}
840 		break;
841 	default:
842 		break;
843 	}
844 	/* there can not be more then one entry for SS Info table */
845 	return result;
846 }
847 
get_soc_bb_info_v4_4(struct bios_parser * bp,struct bp_soc_bb_info * soc_bb_info)848 static enum bp_result get_soc_bb_info_v4_4(
849 	struct bios_parser *bp,
850 	struct bp_soc_bb_info *soc_bb_info)
851 {
852 	enum bp_result result = BP_RESULT_OK;
853 	struct atom_display_controller_info_v4_4 *disp_cntl_tbl = NULL;
854 
855 	if (!soc_bb_info)
856 		return BP_RESULT_BADINPUT;
857 
858 	if (!DATA_TABLES(dce_info))
859 		return BP_RESULT_BADBIOSTABLE;
860 
861 	if (!DATA_TABLES(smu_info))
862 		return BP_RESULT_BADBIOSTABLE;
863 
864 	disp_cntl_tbl =  GET_IMAGE(struct atom_display_controller_info_v4_4,
865 							DATA_TABLES(dce_info));
866 	if (!disp_cntl_tbl)
867 		return BP_RESULT_BADBIOSTABLE;
868 
869 	soc_bb_info->dram_clock_change_latency_100ns = disp_cntl_tbl->max_mclk_chg_lat;
870 	soc_bb_info->dram_sr_enter_exit_latency_100ns = disp_cntl_tbl->max_sr_enter_exit_lat;
871 	soc_bb_info->dram_sr_exit_latency_100ns = disp_cntl_tbl->max_sr_exit_lat;
872 
873 	return result;
874 }
875 
bios_parser_get_soc_bb_info(struct dc_bios * dcb,struct bp_soc_bb_info * soc_bb_info)876 static enum bp_result bios_parser_get_soc_bb_info(
877 	struct dc_bios *dcb,
878 	struct bp_soc_bb_info *soc_bb_info)
879 {
880 	struct bios_parser *bp = BP_FROM_DCB(dcb);
881 	enum bp_result result = BP_RESULT_UNSUPPORTED;
882 	struct atom_common_table_header *header;
883 	struct atom_data_revision tbl_revision;
884 
885 	if (!soc_bb_info) /* check for bad input */
886 		return BP_RESULT_BADINPUT;
887 
888 	if (!DATA_TABLES(dce_info))
889 		return BP_RESULT_UNSUPPORTED;
890 
891 	header = GET_IMAGE(struct atom_common_table_header,
892 						DATA_TABLES(dce_info));
893 	get_atom_data_table_revision(header, &tbl_revision);
894 
895 	switch (tbl_revision.major) {
896 	case 4:
897 		switch (tbl_revision.minor) {
898 		case 1:
899 		case 2:
900 		case 3:
901 			break;
902 		case 4:
903 			result = get_soc_bb_info_v4_4(bp, soc_bb_info);
904 		default:
905 			break;
906 		}
907 		break;
908 	default:
909 		break;
910 	}
911 
912 	return result;
913 }
914 
get_embedded_panel_info_v2_1(struct bios_parser * bp,struct embedded_panel_info * info)915 static enum bp_result get_embedded_panel_info_v2_1(
916 		struct bios_parser *bp,
917 		struct embedded_panel_info *info)
918 {
919 	struct lcd_info_v2_1 *lvds;
920 
921 	if (!info)
922 		return BP_RESULT_BADINPUT;
923 
924 	if (!DATA_TABLES(lcd_info))
925 		return BP_RESULT_UNSUPPORTED;
926 
927 	lvds = GET_IMAGE(struct lcd_info_v2_1, DATA_TABLES(lcd_info));
928 
929 	if (!lvds)
930 		return BP_RESULT_BADBIOSTABLE;
931 
932 	/* TODO: previous vv1_3, should v2_1 */
933 	if (!((lvds->table_header.format_revision == 2)
934 			&& (lvds->table_header.content_revision >= 1)))
935 		return BP_RESULT_UNSUPPORTED;
936 
937 	memset(info, 0, sizeof(struct embedded_panel_info));
938 
939 	/* We need to convert from 10KHz units into KHz units */
940 	info->lcd_timing.pixel_clk = le16_to_cpu(lvds->lcd_timing.pixclk) * 10;
941 	/* usHActive does not include borders, according to VBIOS team */
942 	info->lcd_timing.horizontal_addressable = le16_to_cpu(lvds->lcd_timing.h_active);
943 	/* usHBlanking_Time includes borders, so we should really be
944 	 * subtractingborders duing this translation, but LVDS generally
945 	 * doesn't have borders, so we should be okay leaving this as is for
946 	 * now.  May need to revisit if we ever have LVDS with borders
947 	 */
948 	info->lcd_timing.horizontal_blanking_time = le16_to_cpu(lvds->lcd_timing.h_blanking_time);
949 	/* usVActive does not include borders, according to VBIOS team*/
950 	info->lcd_timing.vertical_addressable = le16_to_cpu(lvds->lcd_timing.v_active);
951 	/* usVBlanking_Time includes borders, so we should really be
952 	 * subtracting borders duing this translation, but LVDS generally
953 	 * doesn't have borders, so we should be okay leaving this as is for
954 	 * now. May need to revisit if we ever have LVDS with borders
955 	 */
956 	info->lcd_timing.vertical_blanking_time = le16_to_cpu(lvds->lcd_timing.v_blanking_time);
957 	info->lcd_timing.horizontal_sync_offset = le16_to_cpu(lvds->lcd_timing.h_sync_offset);
958 	info->lcd_timing.horizontal_sync_width = le16_to_cpu(lvds->lcd_timing.h_sync_width);
959 	info->lcd_timing.vertical_sync_offset = le16_to_cpu(lvds->lcd_timing.v_sync_offset);
960 	info->lcd_timing.vertical_sync_width = le16_to_cpu(lvds->lcd_timing.v_syncwidth);
961 	info->lcd_timing.horizontal_border = lvds->lcd_timing.h_border;
962 	info->lcd_timing.vertical_border = lvds->lcd_timing.v_border;
963 
964 	/* not provided by VBIOS */
965 	info->lcd_timing.misc_info.HORIZONTAL_CUT_OFF = 0;
966 
967 	info->lcd_timing.misc_info.H_SYNC_POLARITY = ~(uint32_t) (lvds->lcd_timing.miscinfo
968 			& ATOM_HSYNC_POLARITY);
969 	info->lcd_timing.misc_info.V_SYNC_POLARITY = ~(uint32_t) (lvds->lcd_timing.miscinfo
970 			& ATOM_VSYNC_POLARITY);
971 
972 	/* not provided by VBIOS */
973 	info->lcd_timing.misc_info.VERTICAL_CUT_OFF = 0;
974 
975 	info->lcd_timing.misc_info.H_REPLICATION_BY2 = !!(lvds->lcd_timing.miscinfo
976 			& ATOM_H_REPLICATIONBY2);
977 	info->lcd_timing.misc_info.V_REPLICATION_BY2 = !!(lvds->lcd_timing.miscinfo
978 			& ATOM_V_REPLICATIONBY2);
979 	info->lcd_timing.misc_info.COMPOSITE_SYNC = !!(lvds->lcd_timing.miscinfo
980 			& ATOM_COMPOSITESYNC);
981 	info->lcd_timing.misc_info.INTERLACE = !!(lvds->lcd_timing.miscinfo & ATOM_INTERLACE);
982 
983 	/* not provided by VBIOS*/
984 	info->lcd_timing.misc_info.DOUBLE_CLOCK = 0;
985 	/* not provided by VBIOS*/
986 	info->ss_id = 0;
987 
988 	info->realtek_eDPToLVDS = !!(lvds->dplvdsrxid == eDP_TO_LVDS_REALTEK_ID);
989 
990 	return BP_RESULT_OK;
991 }
992 
bios_parser_get_embedded_panel_info(struct dc_bios * dcb,struct embedded_panel_info * info)993 static enum bp_result bios_parser_get_embedded_panel_info(
994 		struct dc_bios *dcb,
995 		struct embedded_panel_info *info)
996 {
997 	struct bios_parser
998 	*bp = BP_FROM_DCB(dcb);
999 	struct atom_common_table_header *header;
1000 	struct atom_data_revision tbl_revision;
1001 
1002 	if (!DATA_TABLES(lcd_info))
1003 		return BP_RESULT_FAILURE;
1004 
1005 	header = GET_IMAGE(struct atom_common_table_header, DATA_TABLES(lcd_info));
1006 
1007 	if (!header)
1008 		return BP_RESULT_BADBIOSTABLE;
1009 
1010 	get_atom_data_table_revision(header, &tbl_revision);
1011 
1012 	switch (tbl_revision.major) {
1013 	case 2:
1014 		switch (tbl_revision.minor) {
1015 		case 1:
1016 			return get_embedded_panel_info_v2_1(bp, info);
1017 		default:
1018 			break;
1019 		}
1020 	default:
1021 		break;
1022 	}
1023 
1024 	return BP_RESULT_FAILURE;
1025 }
1026 
get_support_mask_for_device_id(struct device_id device_id)1027 static uint32_t get_support_mask_for_device_id(struct device_id device_id)
1028 {
1029 	enum dal_device_type device_type = device_id.device_type;
1030 	uint32_t enum_id = device_id.enum_id;
1031 
1032 	switch (device_type) {
1033 	case DEVICE_TYPE_LCD:
1034 		switch (enum_id) {
1035 		case 1:
1036 			return ATOM_DISPLAY_LCD1_SUPPORT;
1037 		default:
1038 			break;
1039 		}
1040 		break;
1041 	case DEVICE_TYPE_DFP:
1042 		switch (enum_id) {
1043 		case 1:
1044 			return ATOM_DISPLAY_DFP1_SUPPORT;
1045 		case 2:
1046 			return ATOM_DISPLAY_DFP2_SUPPORT;
1047 		case 3:
1048 			return ATOM_DISPLAY_DFP3_SUPPORT;
1049 		case 4:
1050 			return ATOM_DISPLAY_DFP4_SUPPORT;
1051 		case 5:
1052 			return ATOM_DISPLAY_DFP5_SUPPORT;
1053 		case 6:
1054 			return ATOM_DISPLAY_DFP6_SUPPORT;
1055 		default:
1056 			break;
1057 		}
1058 		break;
1059 	default:
1060 		break;
1061 	}
1062 
1063 	/* Unidentified device ID, return empty support mask. */
1064 	return 0;
1065 }
1066 
bios_parser_is_device_id_supported(struct dc_bios * dcb,struct device_id id)1067 static bool bios_parser_is_device_id_supported(
1068 	struct dc_bios *dcb,
1069 	struct device_id id)
1070 {
1071 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1072 
1073 	uint32_t mask = get_support_mask_for_device_id(id);
1074 
1075 	return (le16_to_cpu(bp->object_info_tbl.v1_4->supporteddevices) &
1076 								mask) != 0;
1077 }
1078 
bios_parser_get_ss_entry_number(struct dc_bios * dcb,enum as_signal_type signal)1079 static uint32_t bios_parser_get_ss_entry_number(
1080 	struct dc_bios *dcb,
1081 	enum as_signal_type signal)
1082 {
1083 	/* TODO: DAL2 atomfirmware implementation does not need this.
1084 	 * why DAL3 need this?
1085 	 */
1086 	return 1;
1087 }
1088 
bios_parser_transmitter_control(struct dc_bios * dcb,struct bp_transmitter_control * cntl)1089 static enum bp_result bios_parser_transmitter_control(
1090 	struct dc_bios *dcb,
1091 	struct bp_transmitter_control *cntl)
1092 {
1093 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1094 
1095 	if (!bp->cmd_tbl.transmitter_control)
1096 		return BP_RESULT_FAILURE;
1097 
1098 	return bp->cmd_tbl.transmitter_control(bp, cntl);
1099 }
1100 
bios_parser_encoder_control(struct dc_bios * dcb,struct bp_encoder_control * cntl)1101 static enum bp_result bios_parser_encoder_control(
1102 	struct dc_bios *dcb,
1103 	struct bp_encoder_control *cntl)
1104 {
1105 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1106 
1107 	if (!bp->cmd_tbl.dig_encoder_control)
1108 		return BP_RESULT_FAILURE;
1109 
1110 	return bp->cmd_tbl.dig_encoder_control(bp, cntl);
1111 }
1112 
bios_parser_set_pixel_clock(struct dc_bios * dcb,struct bp_pixel_clock_parameters * bp_params)1113 static enum bp_result bios_parser_set_pixel_clock(
1114 	struct dc_bios *dcb,
1115 	struct bp_pixel_clock_parameters *bp_params)
1116 {
1117 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1118 
1119 	if (!bp->cmd_tbl.set_pixel_clock)
1120 		return BP_RESULT_FAILURE;
1121 
1122 	return bp->cmd_tbl.set_pixel_clock(bp, bp_params);
1123 }
1124 
bios_parser_set_dce_clock(struct dc_bios * dcb,struct bp_set_dce_clock_parameters * bp_params)1125 static enum bp_result bios_parser_set_dce_clock(
1126 	struct dc_bios *dcb,
1127 	struct bp_set_dce_clock_parameters *bp_params)
1128 {
1129 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1130 
1131 	if (!bp->cmd_tbl.set_dce_clock)
1132 		return BP_RESULT_FAILURE;
1133 
1134 	return bp->cmd_tbl.set_dce_clock(bp, bp_params);
1135 }
1136 
bios_parser_program_crtc_timing(struct dc_bios * dcb,struct bp_hw_crtc_timing_parameters * bp_params)1137 static enum bp_result bios_parser_program_crtc_timing(
1138 	struct dc_bios *dcb,
1139 	struct bp_hw_crtc_timing_parameters *bp_params)
1140 {
1141 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1142 
1143 	if (!bp->cmd_tbl.set_crtc_timing)
1144 		return BP_RESULT_FAILURE;
1145 
1146 	return bp->cmd_tbl.set_crtc_timing(bp, bp_params);
1147 }
1148 
bios_parser_enable_crtc(struct dc_bios * dcb,enum controller_id id,bool enable)1149 static enum bp_result bios_parser_enable_crtc(
1150 	struct dc_bios *dcb,
1151 	enum controller_id id,
1152 	bool enable)
1153 {
1154 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1155 
1156 	if (!bp->cmd_tbl.enable_crtc)
1157 		return BP_RESULT_FAILURE;
1158 
1159 	return bp->cmd_tbl.enable_crtc(bp, id, enable);
1160 }
1161 
bios_parser_enable_disp_power_gating(struct dc_bios * dcb,enum controller_id controller_id,enum bp_pipe_control_action action)1162 static enum bp_result bios_parser_enable_disp_power_gating(
1163 	struct dc_bios *dcb,
1164 	enum controller_id controller_id,
1165 	enum bp_pipe_control_action action)
1166 {
1167 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1168 
1169 	if (!bp->cmd_tbl.enable_disp_power_gating)
1170 		return BP_RESULT_FAILURE;
1171 
1172 	return bp->cmd_tbl.enable_disp_power_gating(bp, controller_id,
1173 		action);
1174 }
1175 
bios_parser_enable_lvtma_control(struct dc_bios * dcb,uint8_t uc_pwr_on)1176 static enum bp_result bios_parser_enable_lvtma_control(
1177 	struct dc_bios *dcb,
1178 	uint8_t uc_pwr_on)
1179 {
1180 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1181 
1182 	if (!bp->cmd_tbl.enable_lvtma_control)
1183 		return BP_RESULT_FAILURE;
1184 
1185 	return bp->cmd_tbl.enable_lvtma_control(bp, uc_pwr_on);
1186 }
1187 
bios_parser_is_accelerated_mode(struct dc_bios * dcb)1188 static bool bios_parser_is_accelerated_mode(
1189 	struct dc_bios *dcb)
1190 {
1191 	return bios_is_accelerated_mode(dcb);
1192 }
1193 
1194 /**
1195  * bios_parser_set_scratch_critical_state
1196  *
1197  * @brief
1198  *  update critical state bit in VBIOS scratch register
1199  *
1200  * @param
1201  *  bool - to set or reset state
1202  */
bios_parser_set_scratch_critical_state(struct dc_bios * dcb,bool state)1203 static void bios_parser_set_scratch_critical_state(
1204 	struct dc_bios *dcb,
1205 	bool state)
1206 {
1207 	bios_set_scratch_critical_state(dcb, state);
1208 }
1209 
bios_parser_get_firmware_info(struct dc_bios * dcb,struct dc_firmware_info * info)1210 static enum bp_result bios_parser_get_firmware_info(
1211 	struct dc_bios *dcb,
1212 	struct dc_firmware_info *info)
1213 {
1214 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1215 	enum bp_result result = BP_RESULT_BADBIOSTABLE;
1216 	struct atom_common_table_header *header;
1217 
1218 	struct atom_data_revision revision;
1219 
1220 	if (info && DATA_TABLES(firmwareinfo)) {
1221 		header = GET_IMAGE(struct atom_common_table_header,
1222 				DATA_TABLES(firmwareinfo));
1223 		get_atom_data_table_revision(header, &revision);
1224 		switch (revision.major) {
1225 		case 3:
1226 			switch (revision.minor) {
1227 			case 1:
1228 				result = get_firmware_info_v3_1(bp, info);
1229 				break;
1230 			case 2:
1231 				result = get_firmware_info_v3_2(bp, info);
1232 				break;
1233 			case 3:
1234 #ifdef CONFIG_DRM_AMD_DC_DCN3_0
1235 			case 4:
1236 #endif
1237 				result = get_firmware_info_v3_2(bp, info);
1238 				break;
1239 			default:
1240 				break;
1241 			}
1242 			break;
1243 		default:
1244 			break;
1245 		}
1246 	}
1247 
1248 	return result;
1249 }
1250 
get_firmware_info_v3_1(struct bios_parser * bp,struct dc_firmware_info * info)1251 static enum bp_result get_firmware_info_v3_1(
1252 	struct bios_parser *bp,
1253 	struct dc_firmware_info *info)
1254 {
1255 	struct atom_firmware_info_v3_1 *firmware_info;
1256 	struct atom_display_controller_info_v4_1 *dce_info = NULL;
1257 
1258 	if (!info)
1259 		return BP_RESULT_BADINPUT;
1260 
1261 	firmware_info = GET_IMAGE(struct atom_firmware_info_v3_1,
1262 			DATA_TABLES(firmwareinfo));
1263 
1264 	dce_info = GET_IMAGE(struct atom_display_controller_info_v4_1,
1265 			DATA_TABLES(dce_info));
1266 
1267 	if (!firmware_info || !dce_info)
1268 		return BP_RESULT_BADBIOSTABLE;
1269 
1270 	memset(info, 0, sizeof(*info));
1271 
1272 	/* Pixel clock pll information. */
1273 	 /* We need to convert from 10KHz units into KHz units */
1274 	info->default_memory_clk = firmware_info->bootup_mclk_in10khz * 10;
1275 	info->default_engine_clk = firmware_info->bootup_sclk_in10khz * 10;
1276 
1277 	 /* 27MHz for Vega10: */
1278 	info->pll_info.crystal_frequency = dce_info->dce_refclk_10khz * 10;
1279 
1280 	/* Hardcode frequency if BIOS gives no DCE Ref Clk */
1281 	if (info->pll_info.crystal_frequency == 0)
1282 		info->pll_info.crystal_frequency = 27000;
1283 	/*dp_phy_ref_clk is not correct for atom_display_controller_info_v4_2, but we don't use it*/
1284 	info->dp_phy_ref_clk     = dce_info->dpphy_refclk_10khz * 10;
1285 	info->i2c_engine_ref_clk = dce_info->i2c_engine_refclk_10khz * 10;
1286 
1287 	/* Get GPU PLL VCO Clock */
1288 
1289 	if (bp->cmd_tbl.get_smu_clock_info != NULL) {
1290 		/* VBIOS gives in 10KHz */
1291 		info->smu_gpu_pll_output_freq =
1292 				bp->cmd_tbl.get_smu_clock_info(bp, SMU9_SYSPLL0_ID) * 10;
1293 	}
1294 
1295 	info->oem_i2c_present = false;
1296 
1297 	return BP_RESULT_OK;
1298 }
1299 
get_firmware_info_v3_2(struct bios_parser * bp,struct dc_firmware_info * info)1300 static enum bp_result get_firmware_info_v3_2(
1301 	struct bios_parser *bp,
1302 	struct dc_firmware_info *info)
1303 {
1304 	struct atom_firmware_info_v3_2 *firmware_info;
1305 	struct atom_display_controller_info_v4_1 *dce_info = NULL;
1306 	struct atom_common_table_header *header;
1307 	struct atom_data_revision revision;
1308 	struct atom_smu_info_v3_2 *smu_info_v3_2 = NULL;
1309 	struct atom_smu_info_v3_3 *smu_info_v3_3 = NULL;
1310 
1311 	if (!info)
1312 		return BP_RESULT_BADINPUT;
1313 
1314 	firmware_info = GET_IMAGE(struct atom_firmware_info_v3_2,
1315 			DATA_TABLES(firmwareinfo));
1316 
1317 	dce_info = GET_IMAGE(struct atom_display_controller_info_v4_1,
1318 			DATA_TABLES(dce_info));
1319 
1320 	if (!firmware_info || !dce_info)
1321 		return BP_RESULT_BADBIOSTABLE;
1322 
1323 	memset(info, 0, sizeof(*info));
1324 
1325 	header = GET_IMAGE(struct atom_common_table_header,
1326 					DATA_TABLES(smu_info));
1327 	get_atom_data_table_revision(header, &revision);
1328 
1329 	if (revision.minor == 2) {
1330 		/* Vega12 */
1331 		smu_info_v3_2 = GET_IMAGE(struct atom_smu_info_v3_2,
1332 							DATA_TABLES(smu_info));
1333 
1334 		if (!smu_info_v3_2)
1335 			return BP_RESULT_BADBIOSTABLE;
1336 
1337 		info->default_engine_clk = smu_info_v3_2->bootup_dcefclk_10khz * 10;
1338 	} else if (revision.minor == 3) {
1339 		/* Vega20 */
1340 		smu_info_v3_3 = GET_IMAGE(struct atom_smu_info_v3_3,
1341 							DATA_TABLES(smu_info));
1342 
1343 		if (!smu_info_v3_3)
1344 			return BP_RESULT_BADBIOSTABLE;
1345 
1346 		info->default_engine_clk = smu_info_v3_3->bootup_dcefclk_10khz * 10;
1347 	}
1348 
1349 	 // We need to convert from 10KHz units into KHz units.
1350 	info->default_memory_clk = firmware_info->bootup_mclk_in10khz * 10;
1351 
1352 	 /* 27MHz for Vega10 & Vega12; 100MHz for Vega20 */
1353 	info->pll_info.crystal_frequency = dce_info->dce_refclk_10khz * 10;
1354 	/* Hardcode frequency if BIOS gives no DCE Ref Clk */
1355 	if (info->pll_info.crystal_frequency == 0) {
1356 		if (revision.minor == 2)
1357 			info->pll_info.crystal_frequency = 27000;
1358 		else if (revision.minor == 3)
1359 			info->pll_info.crystal_frequency = 100000;
1360 	}
1361 	/*dp_phy_ref_clk is not correct for atom_display_controller_info_v4_2, but we don't use it*/
1362 	info->dp_phy_ref_clk     = dce_info->dpphy_refclk_10khz * 10;
1363 	info->i2c_engine_ref_clk = dce_info->i2c_engine_refclk_10khz * 10;
1364 
1365 	/* Get GPU PLL VCO Clock */
1366 	if (bp->cmd_tbl.get_smu_clock_info != NULL) {
1367 		if (revision.minor == 2)
1368 			info->smu_gpu_pll_output_freq =
1369 					bp->cmd_tbl.get_smu_clock_info(bp, SMU9_SYSPLL0_ID) * 10;
1370 		else if (revision.minor == 3)
1371 			info->smu_gpu_pll_output_freq =
1372 					bp->cmd_tbl.get_smu_clock_info(bp, SMU11_SYSPLL3_0_ID) * 10;
1373 	}
1374 
1375 	if (firmware_info->board_i2c_feature_id == 0x2) {
1376 		info->oem_i2c_present = true;
1377 		info->oem_i2c_obj_id = firmware_info->board_i2c_feature_gpio_id;
1378 	} else {
1379 		info->oem_i2c_present = false;
1380 	}
1381 
1382 	return BP_RESULT_OK;
1383 }
1384 
bios_parser_get_encoder_cap_info(struct dc_bios * dcb,struct graphics_object_id object_id,struct bp_encoder_cap_info * info)1385 static enum bp_result bios_parser_get_encoder_cap_info(
1386 	struct dc_bios *dcb,
1387 	struct graphics_object_id object_id,
1388 	struct bp_encoder_cap_info *info)
1389 {
1390 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1391 	struct atom_display_object_path_v2 *object;
1392 	struct atom_encoder_caps_record *record = NULL;
1393 
1394 	if (!info)
1395 		return BP_RESULT_BADINPUT;
1396 
1397 	object = get_bios_object(bp, object_id);
1398 
1399 	if (!object)
1400 		return BP_RESULT_BADINPUT;
1401 
1402 	record = get_encoder_cap_record(bp, object);
1403 	if (!record)
1404 		return BP_RESULT_NORECORD;
1405 
1406 	info->DP_HBR2_CAP = (record->encodercaps &
1407 			ATOM_ENCODER_CAP_RECORD_HBR2) ? 1 : 0;
1408 	info->DP_HBR2_EN = (record->encodercaps &
1409 			ATOM_ENCODER_CAP_RECORD_HBR2_EN) ? 1 : 0;
1410 	info->DP_HBR3_EN = (record->encodercaps &
1411 			ATOM_ENCODER_CAP_RECORD_HBR3_EN) ? 1 : 0;
1412 	info->HDMI_6GB_EN = (record->encodercaps &
1413 			ATOM_ENCODER_CAP_RECORD_HDMI6Gbps_EN) ? 1 : 0;
1414 	info->DP_IS_USB_C = (record->encodercaps &
1415 			ATOM_ENCODER_CAP_RECORD_USB_C_TYPE) ? 1 : 0;
1416 
1417 	return BP_RESULT_OK;
1418 }
1419 
1420 
get_encoder_cap_record(struct bios_parser * bp,struct atom_display_object_path_v2 * object)1421 static struct atom_encoder_caps_record *get_encoder_cap_record(
1422 	struct bios_parser *bp,
1423 	struct atom_display_object_path_v2 *object)
1424 {
1425 	struct atom_common_record_header *header;
1426 	uint32_t offset;
1427 
1428 	if (!object) {
1429 		BREAK_TO_DEBUGGER(); /* Invalid object */
1430 		return NULL;
1431 	}
1432 
1433 	offset = object->encoder_recordoffset + bp->object_info_tbl_offset;
1434 
1435 	for (;;) {
1436 		header = GET_IMAGE(struct atom_common_record_header, offset);
1437 
1438 		if (!header)
1439 			return NULL;
1440 
1441 		offset += header->record_size;
1442 
1443 		if (header->record_type == LAST_RECORD_TYPE ||
1444 				!header->record_size)
1445 			break;
1446 
1447 		if (header->record_type != ATOM_ENCODER_CAP_RECORD_TYPE)
1448 			continue;
1449 
1450 		if (sizeof(struct atom_encoder_caps_record) <=
1451 							header->record_size)
1452 			return (struct atom_encoder_caps_record *)header;
1453 	}
1454 
1455 	return NULL;
1456 }
1457 
get_vram_info_v23(struct bios_parser * bp,struct dc_vram_info * info)1458 static enum bp_result get_vram_info_v23(
1459 	struct bios_parser *bp,
1460 	struct dc_vram_info *info)
1461 {
1462 	struct atom_vram_info_header_v2_3 *info_v23;
1463 	enum bp_result result = BP_RESULT_OK;
1464 
1465 	info_v23 = GET_IMAGE(struct atom_vram_info_header_v2_3,
1466 						DATA_TABLES(vram_info));
1467 
1468 	if (info_v23 == NULL)
1469 		return BP_RESULT_BADBIOSTABLE;
1470 
1471 	info->num_chans = info_v23->vram_module[0].channel_num;
1472 	info->dram_channel_width_bytes = (1 << info_v23->vram_module[0].channel_width) / 8;
1473 
1474 	return result;
1475 }
1476 
get_vram_info_v24(struct bios_parser * bp,struct dc_vram_info * info)1477 static enum bp_result get_vram_info_v24(
1478 	struct bios_parser *bp,
1479 	struct dc_vram_info *info)
1480 {
1481 	struct atom_vram_info_header_v2_4 *info_v24;
1482 	enum bp_result result = BP_RESULT_OK;
1483 
1484 	info_v24 = GET_IMAGE(struct atom_vram_info_header_v2_4,
1485 						DATA_TABLES(vram_info));
1486 
1487 	if (info_v24 == NULL)
1488 		return BP_RESULT_BADBIOSTABLE;
1489 
1490 	info->num_chans = info_v24->vram_module[0].channel_num;
1491 	info->dram_channel_width_bytes = (1 << info_v24->vram_module[0].channel_width) / 8;
1492 
1493 	return result;
1494 }
1495 
get_vram_info_v25(struct bios_parser * bp,struct dc_vram_info * info)1496 static enum bp_result get_vram_info_v25(
1497 	struct bios_parser *bp,
1498 	struct dc_vram_info *info)
1499 {
1500 	struct atom_vram_info_header_v2_5 *info_v25;
1501 	enum bp_result result = BP_RESULT_OK;
1502 
1503 	info_v25 = GET_IMAGE(struct atom_vram_info_header_v2_5,
1504 						DATA_TABLES(vram_info));
1505 
1506 	if (info_v25 == NULL)
1507 		return BP_RESULT_BADBIOSTABLE;
1508 
1509 	info->num_chans = info_v25->vram_module[0].channel_num;
1510 	info->dram_channel_width_bytes = (1 << info_v25->vram_module[0].channel_width) / 8;
1511 
1512 	return result;
1513 }
1514 
1515 /*
1516  * get_integrated_info_v11
1517  *
1518  * @brief
1519  * Get V8 integrated BIOS information
1520  *
1521  * @param
1522  * bios_parser *bp - [in]BIOS parser handler to get master data table
1523  * integrated_info *info - [out] store and output integrated info
1524  *
1525  * @return
1526  * enum bp_result - BP_RESULT_OK if information is available,
1527  *                  BP_RESULT_BADBIOSTABLE otherwise.
1528  */
get_integrated_info_v11(struct bios_parser * bp,struct integrated_info * info)1529 static enum bp_result get_integrated_info_v11(
1530 	struct bios_parser *bp,
1531 	struct integrated_info *info)
1532 {
1533 	struct atom_integrated_system_info_v1_11 *info_v11;
1534 	uint32_t i;
1535 
1536 	info_v11 = GET_IMAGE(struct atom_integrated_system_info_v1_11,
1537 					DATA_TABLES(integratedsysteminfo));
1538 
1539 	if (info_v11 == NULL)
1540 		return BP_RESULT_BADBIOSTABLE;
1541 
1542 	info->gpu_cap_info =
1543 	le32_to_cpu(info_v11->gpucapinfo);
1544 	/*
1545 	* system_config: Bit[0] = 0 : PCIE power gating disabled
1546 	*                       = 1 : PCIE power gating enabled
1547 	*                Bit[1] = 0 : DDR-PLL shut down disabled
1548 	*                       = 1 : DDR-PLL shut down enabled
1549 	*                Bit[2] = 0 : DDR-PLL power down disabled
1550 	*                       = 1 : DDR-PLL power down enabled
1551 	*/
1552 	info->system_config = le32_to_cpu(info_v11->system_config);
1553 	info->cpu_cap_info = le32_to_cpu(info_v11->cpucapinfo);
1554 	info->memory_type = info_v11->memorytype;
1555 	info->ma_channel_number = info_v11->umachannelnumber;
1556 	info->lvds_ss_percentage =
1557 	le16_to_cpu(info_v11->lvds_ss_percentage);
1558 	info->dp_ss_control =
1559 	le16_to_cpu(info_v11->reserved1);
1560 	info->lvds_sspread_rate_in_10hz =
1561 	le16_to_cpu(info_v11->lvds_ss_rate_10hz);
1562 	info->hdmi_ss_percentage =
1563 	le16_to_cpu(info_v11->hdmi_ss_percentage);
1564 	info->hdmi_sspread_rate_in_10hz =
1565 	le16_to_cpu(info_v11->hdmi_ss_rate_10hz);
1566 	info->dvi_ss_percentage =
1567 	le16_to_cpu(info_v11->dvi_ss_percentage);
1568 	info->dvi_sspread_rate_in_10_hz =
1569 	le16_to_cpu(info_v11->dvi_ss_rate_10hz);
1570 	info->lvds_misc = info_v11->lvds_misc;
1571 	for (i = 0; i < NUMBER_OF_UCHAR_FOR_GUID; ++i) {
1572 		info->ext_disp_conn_info.gu_id[i] =
1573 				info_v11->extdispconninfo.guid[i];
1574 	}
1575 
1576 	for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; ++i) {
1577 		info->ext_disp_conn_info.path[i].device_connector_id =
1578 		object_id_from_bios_object_id(
1579 		le16_to_cpu(info_v11->extdispconninfo.path[i].connectorobjid));
1580 
1581 		info->ext_disp_conn_info.path[i].ext_encoder_obj_id =
1582 		object_id_from_bios_object_id(
1583 			le16_to_cpu(
1584 			info_v11->extdispconninfo.path[i].ext_encoder_objid));
1585 
1586 		info->ext_disp_conn_info.path[i].device_tag =
1587 			le16_to_cpu(
1588 				info_v11->extdispconninfo.path[i].device_tag);
1589 		info->ext_disp_conn_info.path[i].device_acpi_enum =
1590 		le16_to_cpu(
1591 			info_v11->extdispconninfo.path[i].device_acpi_enum);
1592 		info->ext_disp_conn_info.path[i].ext_aux_ddc_lut_index =
1593 			info_v11->extdispconninfo.path[i].auxddclut_index;
1594 		info->ext_disp_conn_info.path[i].ext_hpd_pin_lut_index =
1595 			info_v11->extdispconninfo.path[i].hpdlut_index;
1596 		info->ext_disp_conn_info.path[i].channel_mapping.raw =
1597 			info_v11->extdispconninfo.path[i].channelmapping;
1598 		info->ext_disp_conn_info.path[i].caps =
1599 				le16_to_cpu(info_v11->extdispconninfo.path[i].caps);
1600 	}
1601 	info->ext_disp_conn_info.checksum =
1602 	info_v11->extdispconninfo.checksum;
1603 
1604 	info->dp0_ext_hdmi_slv_addr = info_v11->dp0_retimer_set.HdmiSlvAddr;
1605 	info->dp0_ext_hdmi_reg_num = info_v11->dp0_retimer_set.HdmiRegNum;
1606 	for (i = 0; i < info->dp0_ext_hdmi_reg_num; i++) {
1607 		info->dp0_ext_hdmi_reg_settings[i].i2c_reg_index =
1608 				info_v11->dp0_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
1609 		info->dp0_ext_hdmi_reg_settings[i].i2c_reg_val =
1610 				info_v11->dp0_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
1611 	}
1612 	info->dp0_ext_hdmi_6g_reg_num = info_v11->dp0_retimer_set.Hdmi6GRegNum;
1613 	for (i = 0; i < info->dp0_ext_hdmi_6g_reg_num; i++) {
1614 		info->dp0_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
1615 				info_v11->dp0_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
1616 		info->dp0_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
1617 				info_v11->dp0_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
1618 	}
1619 
1620 	info->dp1_ext_hdmi_slv_addr = info_v11->dp1_retimer_set.HdmiSlvAddr;
1621 	info->dp1_ext_hdmi_reg_num = info_v11->dp1_retimer_set.HdmiRegNum;
1622 	for (i = 0; i < info->dp1_ext_hdmi_reg_num; i++) {
1623 		info->dp1_ext_hdmi_reg_settings[i].i2c_reg_index =
1624 				info_v11->dp1_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
1625 		info->dp1_ext_hdmi_reg_settings[i].i2c_reg_val =
1626 				info_v11->dp1_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
1627 	}
1628 	info->dp1_ext_hdmi_6g_reg_num = info_v11->dp1_retimer_set.Hdmi6GRegNum;
1629 	for (i = 0; i < info->dp1_ext_hdmi_6g_reg_num; i++) {
1630 		info->dp1_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
1631 				info_v11->dp1_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
1632 		info->dp1_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
1633 				info_v11->dp1_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
1634 	}
1635 
1636 	info->dp2_ext_hdmi_slv_addr = info_v11->dp2_retimer_set.HdmiSlvAddr;
1637 	info->dp2_ext_hdmi_reg_num = info_v11->dp2_retimer_set.HdmiRegNum;
1638 	for (i = 0; i < info->dp2_ext_hdmi_reg_num; i++) {
1639 		info->dp2_ext_hdmi_reg_settings[i].i2c_reg_index =
1640 				info_v11->dp2_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
1641 		info->dp2_ext_hdmi_reg_settings[i].i2c_reg_val =
1642 				info_v11->dp2_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
1643 	}
1644 	info->dp2_ext_hdmi_6g_reg_num = info_v11->dp2_retimer_set.Hdmi6GRegNum;
1645 	for (i = 0; i < info->dp2_ext_hdmi_6g_reg_num; i++) {
1646 		info->dp2_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
1647 				info_v11->dp2_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
1648 		info->dp2_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
1649 				info_v11->dp2_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
1650 	}
1651 
1652 	info->dp3_ext_hdmi_slv_addr = info_v11->dp3_retimer_set.HdmiSlvAddr;
1653 	info->dp3_ext_hdmi_reg_num = info_v11->dp3_retimer_set.HdmiRegNum;
1654 	for (i = 0; i < info->dp3_ext_hdmi_reg_num; i++) {
1655 		info->dp3_ext_hdmi_reg_settings[i].i2c_reg_index =
1656 				info_v11->dp3_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
1657 		info->dp3_ext_hdmi_reg_settings[i].i2c_reg_val =
1658 				info_v11->dp3_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
1659 	}
1660 	info->dp3_ext_hdmi_6g_reg_num = info_v11->dp3_retimer_set.Hdmi6GRegNum;
1661 	for (i = 0; i < info->dp3_ext_hdmi_6g_reg_num; i++) {
1662 		info->dp3_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
1663 				info_v11->dp3_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
1664 		info->dp3_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
1665 				info_v11->dp3_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
1666 	}
1667 
1668 
1669 	/** TODO - review **/
1670 	#if 0
1671 	info->boot_up_engine_clock = le32_to_cpu(info_v11->ulBootUpEngineClock)
1672 									* 10;
1673 	info->dentist_vco_freq = le32_to_cpu(info_v11->ulDentistVCOFreq) * 10;
1674 	info->boot_up_uma_clock = le32_to_cpu(info_v8->ulBootUpUMAClock) * 10;
1675 
1676 	for (i = 0; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
1677 		/* Convert [10KHz] into [KHz] */
1678 		info->disp_clk_voltage[i].max_supported_clk =
1679 		le32_to_cpu(info_v11->sDISPCLK_Voltage[i].
1680 			ulMaximumSupportedCLK) * 10;
1681 		info->disp_clk_voltage[i].voltage_index =
1682 		le32_to_cpu(info_v11->sDISPCLK_Voltage[i].ulVoltageIndex);
1683 	}
1684 
1685 	info->boot_up_req_display_vector =
1686 			le32_to_cpu(info_v11->ulBootUpReqDisplayVector);
1687 	info->boot_up_nb_voltage =
1688 			le16_to_cpu(info_v11->usBootUpNBVoltage);
1689 	info->ext_disp_conn_info_offset =
1690 			le16_to_cpu(info_v11->usExtDispConnInfoOffset);
1691 	info->gmc_restore_reset_time =
1692 			le32_to_cpu(info_v11->ulGMCRestoreResetTime);
1693 	info->minimum_n_clk =
1694 			le32_to_cpu(info_v11->ulNbpStateNClkFreq[0]);
1695 	for (i = 1; i < 4; ++i)
1696 		info->minimum_n_clk =
1697 				info->minimum_n_clk <
1698 				le32_to_cpu(info_v11->ulNbpStateNClkFreq[i]) ?
1699 				info->minimum_n_clk : le32_to_cpu(
1700 					info_v11->ulNbpStateNClkFreq[i]);
1701 
1702 	info->idle_n_clk = le32_to_cpu(info_v11->ulIdleNClk);
1703 	info->ddr_dll_power_up_time =
1704 	    le32_to_cpu(info_v11->ulDDR_DLL_PowerUpTime);
1705 	info->ddr_pll_power_up_time =
1706 		le32_to_cpu(info_v11->ulDDR_PLL_PowerUpTime);
1707 	info->pcie_clk_ss_type = le16_to_cpu(info_v11->usPCIEClkSSType);
1708 	info->max_lvds_pclk_freq_in_single_link =
1709 		le16_to_cpu(info_v11->usMaxLVDSPclkFreqInSingleLink);
1710 	info->max_lvds_pclk_freq_in_single_link =
1711 		le16_to_cpu(info_v11->usMaxLVDSPclkFreqInSingleLink);
1712 	info->lvds_pwr_on_seq_dig_on_to_de_in_4ms =
1713 		info_v11->ucLVDSPwrOnSeqDIGONtoDE_in4Ms;
1714 	info->lvds_pwr_on_seq_de_to_vary_bl_in_4ms =
1715 		info_v11->ucLVDSPwrOnSeqDEtoVARY_BL_in4Ms;
1716 	info->lvds_pwr_on_seq_vary_bl_to_blon_in_4ms =
1717 		info_v11->ucLVDSPwrOnSeqVARY_BLtoBLON_in4Ms;
1718 	info->lvds_pwr_off_seq_vary_bl_to_de_in4ms =
1719 		info_v11->ucLVDSPwrOffSeqVARY_BLtoDE_in4Ms;
1720 	info->lvds_pwr_off_seq_de_to_dig_on_in4ms =
1721 		info_v11->ucLVDSPwrOffSeqDEtoDIGON_in4Ms;
1722 	info->lvds_pwr_off_seq_blon_to_vary_bl_in_4ms =
1723 		info_v11->ucLVDSPwrOffSeqBLONtoVARY_BL_in4Ms;
1724 	info->lvds_off_to_on_delay_in_4ms =
1725 		info_v11->ucLVDSOffToOnDelay_in4Ms;
1726 	info->lvds_bit_depth_control_val =
1727 		le32_to_cpu(info_v11->ulLCDBitDepthControlVal);
1728 
1729 	for (i = 0; i < NUMBER_OF_AVAILABLE_SCLK; ++i) {
1730 		/* Convert [10KHz] into [KHz] */
1731 		info->avail_s_clk[i].supported_s_clk =
1732 			le32_to_cpu(info_v11->sAvail_SCLK[i].ulSupportedSCLK)
1733 									* 10;
1734 		info->avail_s_clk[i].voltage_index =
1735 			le16_to_cpu(info_v11->sAvail_SCLK[i].usVoltageIndex);
1736 		info->avail_s_clk[i].voltage_id =
1737 			le16_to_cpu(info_v11->sAvail_SCLK[i].usVoltageID);
1738 	}
1739 	#endif /* TODO*/
1740 
1741 	return BP_RESULT_OK;
1742 }
1743 
1744 
1745 /*
1746  * construct_integrated_info
1747  *
1748  * @brief
1749  * Get integrated BIOS information based on table revision
1750  *
1751  * @param
1752  * bios_parser *bp - [in]BIOS parser handler to get master data table
1753  * integrated_info *info - [out] store and output integrated info
1754  *
1755  * @return
1756  * enum bp_result - BP_RESULT_OK if information is available,
1757  *                  BP_RESULT_BADBIOSTABLE otherwise.
1758  */
construct_integrated_info(struct bios_parser * bp,struct integrated_info * info)1759 static enum bp_result construct_integrated_info(
1760 	struct bios_parser *bp,
1761 	struct integrated_info *info)
1762 {
1763 	enum bp_result result = BP_RESULT_BADBIOSTABLE;
1764 
1765 	struct atom_common_table_header *header;
1766 	struct atom_data_revision revision;
1767 	uint32_t i;
1768 	uint32_t j;
1769 
1770 	if (info && DATA_TABLES(integratedsysteminfo)) {
1771 		header = GET_IMAGE(struct atom_common_table_header,
1772 					DATA_TABLES(integratedsysteminfo));
1773 
1774 		get_atom_data_table_revision(header, &revision);
1775 
1776 		/* Don't need to check major revision as they are all 1 */
1777 		switch (revision.minor) {
1778 		case 11:
1779 		case 12:
1780 			result = get_integrated_info_v11(bp, info);
1781 			break;
1782 		default:
1783 			return result;
1784 		}
1785 	}
1786 
1787 	if (result != BP_RESULT_OK)
1788 		return result;
1789 
1790 	/* Sort voltage table from low to high*/
1791 	for (i = 1; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
1792 		for (j = i; j > 0; --j) {
1793 			if (info->disp_clk_voltage[j].max_supported_clk <
1794 				info->disp_clk_voltage[j-1].max_supported_clk
1795 				) {
1796 				/* swap j and j - 1*/
1797 				swap(info->disp_clk_voltage[j - 1],
1798 				     info->disp_clk_voltage[j]);
1799 			}
1800 		}
1801 	}
1802 
1803 	return result;
1804 }
1805 
bios_parser_get_vram_info(struct dc_bios * dcb,struct dc_vram_info * info)1806 static enum bp_result bios_parser_get_vram_info(
1807 		struct dc_bios *dcb,
1808 		struct dc_vram_info *info)
1809 {
1810 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1811 	enum bp_result result = BP_RESULT_BADBIOSTABLE;
1812 	struct atom_common_table_header *header;
1813 	struct atom_data_revision revision;
1814 
1815 	if (info && DATA_TABLES(vram_info)) {
1816 		header = GET_IMAGE(struct atom_common_table_header,
1817 					DATA_TABLES(vram_info));
1818 
1819 		get_atom_data_table_revision(header, &revision);
1820 
1821 		switch (revision.major) {
1822 		case 2:
1823 			switch (revision.minor) {
1824 			case 3:
1825 				result = get_vram_info_v23(bp, info);
1826 				break;
1827 			case 4:
1828 				result = get_vram_info_v24(bp, info);
1829 				break;
1830 			case 5:
1831 				result = get_vram_info_v25(bp, info);
1832 				break;
1833 			default:
1834 				break;
1835 			}
1836 			break;
1837 
1838 		default:
1839 			return result;
1840 		}
1841 
1842 	}
1843 	return result;
1844 }
1845 
bios_parser_create_integrated_info(struct dc_bios * dcb)1846 static struct integrated_info *bios_parser_create_integrated_info(
1847 	struct dc_bios *dcb)
1848 {
1849 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1850 	struct integrated_info *info = NULL;
1851 
1852 	info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);
1853 
1854 	if (info == NULL) {
1855 		ASSERT_CRITICAL(0);
1856 		return NULL;
1857 	}
1858 
1859 	if (construct_integrated_info(bp, info) == BP_RESULT_OK)
1860 		return info;
1861 
1862 	kfree(info);
1863 
1864 	return NULL;
1865 }
1866 
update_slot_layout_info(struct dc_bios * dcb,unsigned int i,struct slot_layout_info * slot_layout_info)1867 static enum bp_result update_slot_layout_info(
1868 	struct dc_bios *dcb,
1869 	unsigned int i,
1870 	struct slot_layout_info *slot_layout_info)
1871 {
1872 	unsigned int record_offset;
1873 	unsigned int j;
1874 	struct atom_display_object_path_v2 *object;
1875 	struct atom_bracket_layout_record *record;
1876 	struct atom_common_record_header *record_header;
1877 	enum bp_result result;
1878 	struct bios_parser *bp;
1879 	struct object_info_table *tbl;
1880 	struct display_object_info_table_v1_4 *v1_4;
1881 
1882 	record = NULL;
1883 	record_header = NULL;
1884 	result = BP_RESULT_NORECORD;
1885 
1886 	bp = BP_FROM_DCB(dcb);
1887 	tbl = &bp->object_info_tbl;
1888 	v1_4 = tbl->v1_4;
1889 
1890 	object = &v1_4->display_path[i];
1891 	record_offset = (unsigned int)
1892 		(object->disp_recordoffset) +
1893 		(unsigned int)(bp->object_info_tbl_offset);
1894 
1895 	for (;;) {
1896 
1897 		record_header = (struct atom_common_record_header *)
1898 			GET_IMAGE(struct atom_common_record_header,
1899 			record_offset);
1900 		if (record_header == NULL) {
1901 			result = BP_RESULT_BADBIOSTABLE;
1902 			break;
1903 		}
1904 
1905 		/* the end of the list */
1906 		if (record_header->record_type == 0xff ||
1907 			record_header->record_size == 0)	{
1908 			break;
1909 		}
1910 
1911 		if (record_header->record_type ==
1912 			ATOM_BRACKET_LAYOUT_RECORD_TYPE &&
1913 			sizeof(struct atom_bracket_layout_record)
1914 			<= record_header->record_size) {
1915 			record = (struct atom_bracket_layout_record *)
1916 				(record_header);
1917 			result = BP_RESULT_OK;
1918 			break;
1919 		}
1920 
1921 		record_offset += record_header->record_size;
1922 	}
1923 
1924 	/* return if the record not found */
1925 	if (result != BP_RESULT_OK)
1926 		return result;
1927 
1928 	/* get slot sizes */
1929 	slot_layout_info->length = record->bracketlen;
1930 	slot_layout_info->width = record->bracketwidth;
1931 
1932 	/* get info for each connector in the slot */
1933 	slot_layout_info->num_of_connectors = record->conn_num;
1934 	for (j = 0; j < slot_layout_info->num_of_connectors; ++j) {
1935 		slot_layout_info->connectors[j].connector_type =
1936 			(enum connector_layout_type)
1937 			(record->conn_info[j].connector_type);
1938 		switch (record->conn_info[j].connector_type) {
1939 		case CONNECTOR_TYPE_DVI_D:
1940 			slot_layout_info->connectors[j].connector_type =
1941 				CONNECTOR_LAYOUT_TYPE_DVI_D;
1942 			slot_layout_info->connectors[j].length =
1943 				CONNECTOR_SIZE_DVI;
1944 			break;
1945 
1946 		case CONNECTOR_TYPE_HDMI:
1947 			slot_layout_info->connectors[j].connector_type =
1948 				CONNECTOR_LAYOUT_TYPE_HDMI;
1949 			slot_layout_info->connectors[j].length =
1950 				CONNECTOR_SIZE_HDMI;
1951 			break;
1952 
1953 		case CONNECTOR_TYPE_DISPLAY_PORT:
1954 			slot_layout_info->connectors[j].connector_type =
1955 				CONNECTOR_LAYOUT_TYPE_DP;
1956 			slot_layout_info->connectors[j].length =
1957 				CONNECTOR_SIZE_DP;
1958 			break;
1959 
1960 		case CONNECTOR_TYPE_MINI_DISPLAY_PORT:
1961 			slot_layout_info->connectors[j].connector_type =
1962 				CONNECTOR_LAYOUT_TYPE_MINI_DP;
1963 			slot_layout_info->connectors[j].length =
1964 				CONNECTOR_SIZE_MINI_DP;
1965 			break;
1966 
1967 		default:
1968 			slot_layout_info->connectors[j].connector_type =
1969 				CONNECTOR_LAYOUT_TYPE_UNKNOWN;
1970 			slot_layout_info->connectors[j].length =
1971 				CONNECTOR_SIZE_UNKNOWN;
1972 		}
1973 
1974 		slot_layout_info->connectors[j].position =
1975 			record->conn_info[j].position;
1976 		slot_layout_info->connectors[j].connector_id =
1977 			object_id_from_bios_object_id(
1978 				record->conn_info[j].connectorobjid);
1979 	}
1980 	return result;
1981 }
1982 
1983 
get_bracket_layout_record(struct dc_bios * dcb,unsigned int bracket_layout_id,struct slot_layout_info * slot_layout_info)1984 static enum bp_result get_bracket_layout_record(
1985 	struct dc_bios *dcb,
1986 	unsigned int bracket_layout_id,
1987 	struct slot_layout_info *slot_layout_info)
1988 {
1989 	unsigned int i;
1990 	struct bios_parser *bp = BP_FROM_DCB(dcb);
1991 	enum bp_result result;
1992 	struct object_info_table *tbl;
1993 	struct display_object_info_table_v1_4 *v1_4;
1994 
1995 	if (slot_layout_info == NULL) {
1996 		DC_LOG_DETECTION_EDID_PARSER("Invalid slot_layout_info\n");
1997 		return BP_RESULT_BADINPUT;
1998 	}
1999 	tbl = &bp->object_info_tbl;
2000 	v1_4 = tbl->v1_4;
2001 
2002 	result = BP_RESULT_NORECORD;
2003 	for (i = 0; i < v1_4->number_of_path; ++i)	{
2004 
2005 		if (bracket_layout_id ==
2006 			v1_4->display_path[i].display_objid) {
2007 			result = update_slot_layout_info(dcb, i,
2008 				slot_layout_info);
2009 			break;
2010 		}
2011 	}
2012 	return result;
2013 }
2014 
bios_get_board_layout_info(struct dc_bios * dcb,struct board_layout_info * board_layout_info)2015 static enum bp_result bios_get_board_layout_info(
2016 	struct dc_bios *dcb,
2017 	struct board_layout_info *board_layout_info)
2018 {
2019 	unsigned int i;
2020 	enum bp_result record_result;
2021 
2022 	const unsigned int slot_index_to_vbios_id[MAX_BOARD_SLOTS] = {
2023 		GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID1,
2024 		GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID2,
2025 		0, 0
2026 	};
2027 
2028 	if (board_layout_info == NULL) {
2029 		DC_LOG_DETECTION_EDID_PARSER("Invalid board_layout_info\n");
2030 		return BP_RESULT_BADINPUT;
2031 	}
2032 
2033 	board_layout_info->num_of_slots = 0;
2034 
2035 	for (i = 0; i < MAX_BOARD_SLOTS; ++i) {
2036 		record_result = get_bracket_layout_record(dcb,
2037 			slot_index_to_vbios_id[i],
2038 			&board_layout_info->slots[i]);
2039 
2040 		if (record_result == BP_RESULT_NORECORD && i > 0)
2041 			break; /* no more slots present in bios */
2042 		else if (record_result != BP_RESULT_OK)
2043 			return record_result;  /* fail */
2044 
2045 		++board_layout_info->num_of_slots;
2046 	}
2047 
2048 	/* all data is valid */
2049 	board_layout_info->is_number_of_slots_valid = 1;
2050 	board_layout_info->is_slots_size_valid = 1;
2051 	board_layout_info->is_connector_offsets_valid = 1;
2052 	board_layout_info->is_connector_lengths_valid = 1;
2053 
2054 	return BP_RESULT_OK;
2055 }
2056 
2057 
bios_parser_pack_data_tables(struct dc_bios * dcb,void * dst)2058 static uint16_t bios_parser_pack_data_tables(
2059 	struct dc_bios *dcb,
2060 	void *dst)
2061 {
2062 #ifdef PACK_BIOS_DATA
2063 	struct bios_parser *bp = BP_FROM_DCB(dcb);
2064 	struct atom_rom_header_v2_2 *rom_header = NULL;
2065 	struct atom_rom_header_v2_2 *packed_rom_header = NULL;
2066 	struct atom_common_table_header *data_tbl_header = NULL;
2067 	struct atom_master_list_of_data_tables_v2_1 *data_tbl_list = NULL;
2068 	struct atom_master_data_table_v2_1 *packed_master_data_tbl = NULL;
2069 	struct atom_data_revision tbl_rev = {0};
2070 	uint16_t *rom_header_offset = NULL;
2071 	const uint8_t *bios = bp->base.bios;
2072 	uint8_t *bios_dst = (uint8_t *)dst;
2073 	uint16_t packed_rom_header_offset;
2074 	uint16_t packed_masterdatatable_offset;
2075 	uint16_t packed_data_tbl_offset;
2076 	uint16_t data_tbl_offset;
2077 	unsigned int i;
2078 
2079 	rom_header_offset =
2080 		GET_IMAGE(uint16_t, OFFSET_TO_ATOM_ROM_HEADER_POINTER);
2081 
2082 	if (!rom_header_offset)
2083 		return 0;
2084 
2085 	rom_header = GET_IMAGE(struct atom_rom_header_v2_2, *rom_header_offset);
2086 
2087 	if (!rom_header)
2088 		return 0;
2089 
2090 	get_atom_data_table_revision(&rom_header->table_header, &tbl_rev);
2091 	if (!(tbl_rev.major >= 2 && tbl_rev.minor >= 2))
2092 		return 0;
2093 
2094 	get_atom_data_table_revision(&bp->master_data_tbl->table_header, &tbl_rev);
2095 	if (!(tbl_rev.major >= 2 && tbl_rev.minor >= 1))
2096 		return 0;
2097 
2098 	packed_rom_header_offset =
2099 		OFFSET_TO_ATOM_ROM_HEADER_POINTER + sizeof(*rom_header_offset);
2100 
2101 	packed_masterdatatable_offset =
2102 		packed_rom_header_offset + rom_header->table_header.structuresize;
2103 
2104 	packed_data_tbl_offset =
2105 		packed_masterdatatable_offset +
2106 		bp->master_data_tbl->table_header.structuresize;
2107 
2108 	packed_rom_header =
2109 		(struct atom_rom_header_v2_2 *)(bios_dst + packed_rom_header_offset);
2110 
2111 	packed_master_data_tbl =
2112 		(struct atom_master_data_table_v2_1 *)(bios_dst +
2113 		packed_masterdatatable_offset);
2114 
2115 	memcpy(bios_dst, bios, OFFSET_TO_ATOM_ROM_HEADER_POINTER);
2116 
2117 	*((uint16_t *)(bios_dst + OFFSET_TO_ATOM_ROM_HEADER_POINTER)) =
2118 		packed_rom_header_offset;
2119 
2120 	memcpy(bios_dst + packed_rom_header_offset, rom_header,
2121 		rom_header->table_header.structuresize);
2122 
2123 	packed_rom_header->masterdatatable_offset = packed_masterdatatable_offset;
2124 
2125 	memcpy(&packed_master_data_tbl->table_header,
2126 		&bp->master_data_tbl->table_header,
2127 		sizeof(bp->master_data_tbl->table_header));
2128 
2129 	data_tbl_list = &bp->master_data_tbl->listOfdatatables;
2130 
2131 	/* Each data table offset in data table list is 2 bytes,
2132 	 * we can use that to iterate through listOfdatatables
2133 	 * without knowing the name of each member.
2134 	 */
2135 	for (i = 0; i < sizeof(*data_tbl_list)/sizeof(uint16_t); i++) {
2136 		data_tbl_offset = *((uint16_t *)data_tbl_list + i);
2137 
2138 		if (data_tbl_offset) {
2139 			data_tbl_header =
2140 				(struct atom_common_table_header *)(bios + data_tbl_offset);
2141 
2142 			memcpy(bios_dst + packed_data_tbl_offset, data_tbl_header,
2143 				data_tbl_header->structuresize);
2144 
2145 			*((uint16_t *)&packed_master_data_tbl->listOfdatatables + i) =
2146 				packed_data_tbl_offset;
2147 
2148 			packed_data_tbl_offset += data_tbl_header->structuresize;
2149 		} else {
2150 			*((uint16_t *)&packed_master_data_tbl->listOfdatatables + i) = 0;
2151 		}
2152 	}
2153 	return packed_data_tbl_offset;
2154 #endif
2155 	// TODO: There is data bytes alignment issue, disable it for now.
2156 	return 0;
2157 }
2158 
bios_get_golden_table(struct bios_parser * bp,uint32_t rev_major,uint32_t rev_minor,uint16_t * dc_golden_table_ver)2159 static struct atom_dc_golden_table_v1 *bios_get_golden_table(
2160 		struct bios_parser *bp,
2161 		uint32_t rev_major,
2162 		uint32_t rev_minor,
2163 		uint16_t *dc_golden_table_ver)
2164 {
2165 	struct atom_display_controller_info_v4_4 *disp_cntl_tbl_4_4 = NULL;
2166 	uint32_t dc_golden_offset = 0;
2167 	*dc_golden_table_ver = 0;
2168 
2169 	if (!DATA_TABLES(dce_info))
2170 		return NULL;
2171 
2172 	/* ver.4.4 or higher */
2173 	switch (rev_major) {
2174 	case 4:
2175 		switch (rev_minor) {
2176 		case 4:
2177 			disp_cntl_tbl_4_4 = GET_IMAGE(struct atom_display_controller_info_v4_4,
2178 									DATA_TABLES(dce_info));
2179 			if (!disp_cntl_tbl_4_4)
2180 				return NULL;
2181 			dc_golden_offset = DATA_TABLES(dce_info) + disp_cntl_tbl_4_4->dc_golden_table_offset;
2182 			*dc_golden_table_ver = disp_cntl_tbl_4_4->dc_golden_table_ver;
2183 			break;
2184 		}
2185 		break;
2186 	}
2187 
2188 	if (!dc_golden_offset)
2189 		return NULL;
2190 
2191 	if (*dc_golden_table_ver != 1)
2192 		return NULL;
2193 
2194 	return GET_IMAGE(struct atom_dc_golden_table_v1,
2195 			dc_golden_offset);
2196 }
2197 
bios_get_atom_dc_golden_table(struct dc_bios * dcb)2198 static enum bp_result bios_get_atom_dc_golden_table(
2199 	struct dc_bios *dcb)
2200 {
2201 	struct bios_parser *bp = BP_FROM_DCB(dcb);
2202 	enum bp_result result = BP_RESULT_OK;
2203 	struct atom_dc_golden_table_v1 *atom_dc_golden_table = NULL;
2204 	struct atom_common_table_header *header;
2205 	struct atom_data_revision tbl_revision;
2206 	uint16_t dc_golden_table_ver = 0;
2207 
2208 	header = GET_IMAGE(struct atom_common_table_header,
2209 							DATA_TABLES(dce_info));
2210 	if (!header)
2211 		return BP_RESULT_UNSUPPORTED;
2212 
2213 	get_atom_data_table_revision(header, &tbl_revision);
2214 
2215 	atom_dc_golden_table = bios_get_golden_table(bp,
2216 			tbl_revision.major,
2217 			tbl_revision.minor,
2218 			&dc_golden_table_ver);
2219 
2220 	if (!atom_dc_golden_table)
2221 		return BP_RESULT_UNSUPPORTED;
2222 
2223 	dcb->golden_table.dc_golden_table_ver = dc_golden_table_ver;
2224 	dcb->golden_table.aux_dphy_rx_control0_val = atom_dc_golden_table->aux_dphy_rx_control0_val;
2225 	dcb->golden_table.aux_dphy_rx_control1_val = atom_dc_golden_table->aux_dphy_rx_control1_val;
2226 	dcb->golden_table.aux_dphy_tx_control_val = atom_dc_golden_table->aux_dphy_tx_control_val;
2227 	dcb->golden_table.dc_gpio_aux_ctrl_0_val = atom_dc_golden_table->dc_gpio_aux_ctrl_0_val;
2228 	dcb->golden_table.dc_gpio_aux_ctrl_1_val = atom_dc_golden_table->dc_gpio_aux_ctrl_1_val;
2229 	dcb->golden_table.dc_gpio_aux_ctrl_2_val = atom_dc_golden_table->dc_gpio_aux_ctrl_2_val;
2230 	dcb->golden_table.dc_gpio_aux_ctrl_3_val = atom_dc_golden_table->dc_gpio_aux_ctrl_3_val;
2231 	dcb->golden_table.dc_gpio_aux_ctrl_4_val = atom_dc_golden_table->dc_gpio_aux_ctrl_4_val;
2232 	dcb->golden_table.dc_gpio_aux_ctrl_5_val = atom_dc_golden_table->dc_gpio_aux_ctrl_5_val;
2233 
2234 	return result;
2235 }
2236 
2237 
2238 static const struct dc_vbios_funcs vbios_funcs = {
2239 	.get_connectors_number = bios_parser_get_connectors_number,
2240 
2241 	.get_connector_id = bios_parser_get_connector_id,
2242 
2243 	.get_src_obj = bios_parser_get_src_obj,
2244 
2245 	.get_i2c_info = bios_parser_get_i2c_info,
2246 
2247 	.get_hpd_info = bios_parser_get_hpd_info,
2248 
2249 	.get_device_tag = bios_parser_get_device_tag,
2250 
2251 	.get_spread_spectrum_info = bios_parser_get_spread_spectrum_info,
2252 
2253 	.get_ss_entry_number = bios_parser_get_ss_entry_number,
2254 
2255 	.get_embedded_panel_info = bios_parser_get_embedded_panel_info,
2256 
2257 	.get_gpio_pin_info = bios_parser_get_gpio_pin_info,
2258 
2259 	.get_encoder_cap_info = bios_parser_get_encoder_cap_info,
2260 
2261 	.is_device_id_supported = bios_parser_is_device_id_supported,
2262 
2263 	.is_accelerated_mode = bios_parser_is_accelerated_mode,
2264 
2265 	.set_scratch_critical_state = bios_parser_set_scratch_critical_state,
2266 
2267 
2268 /*	 COMMANDS */
2269 	.encoder_control = bios_parser_encoder_control,
2270 
2271 	.transmitter_control = bios_parser_transmitter_control,
2272 
2273 	.enable_crtc = bios_parser_enable_crtc,
2274 
2275 	.set_pixel_clock = bios_parser_set_pixel_clock,
2276 
2277 	.set_dce_clock = bios_parser_set_dce_clock,
2278 
2279 	.program_crtc_timing = bios_parser_program_crtc_timing,
2280 
2281 	.enable_disp_power_gating = bios_parser_enable_disp_power_gating,
2282 
2283 	.bios_parser_destroy = firmware_parser_destroy,
2284 
2285 	.get_board_layout_info = bios_get_board_layout_info,
2286 	.pack_data_tables = bios_parser_pack_data_tables,
2287 
2288 	.get_atom_dc_golden_table = bios_get_atom_dc_golden_table,
2289 
2290 	.enable_lvtma_control = bios_parser_enable_lvtma_control,
2291 
2292 	.get_soc_bb_info = bios_parser_get_soc_bb_info,
2293 };
2294 
bios_parser2_construct(struct bios_parser * bp,struct bp_init_data * init,enum dce_version dce_version)2295 static bool bios_parser2_construct(
2296 	struct bios_parser *bp,
2297 	struct bp_init_data *init,
2298 	enum dce_version dce_version)
2299 {
2300 	uint16_t *rom_header_offset = NULL;
2301 	struct atom_rom_header_v2_2 *rom_header = NULL;
2302 	struct display_object_info_table_v1_4 *object_info_tbl;
2303 	struct atom_data_revision tbl_rev = {0};
2304 
2305 	if (!init)
2306 		return false;
2307 
2308 	if (!init->bios)
2309 		return false;
2310 
2311 	bp->base.funcs = &vbios_funcs;
2312 	bp->base.bios = init->bios;
2313 	bp->base.bios_size = bp->base.bios[OFFSET_TO_ATOM_ROM_IMAGE_SIZE] * BIOS_IMAGE_SIZE_UNIT;
2314 
2315 	bp->base.ctx = init->ctx;
2316 
2317 	bp->base.bios_local_image = NULL;
2318 
2319 	rom_header_offset =
2320 			GET_IMAGE(uint16_t, OFFSET_TO_ATOM_ROM_HEADER_POINTER);
2321 
2322 	if (!rom_header_offset)
2323 		return false;
2324 
2325 	rom_header = GET_IMAGE(struct atom_rom_header_v2_2, *rom_header_offset);
2326 
2327 	if (!rom_header)
2328 		return false;
2329 
2330 	get_atom_data_table_revision(&rom_header->table_header, &tbl_rev);
2331 	if (!(tbl_rev.major >= 2 && tbl_rev.minor >= 2))
2332 		return false;
2333 
2334 	bp->master_data_tbl =
2335 		GET_IMAGE(struct atom_master_data_table_v2_1,
2336 				rom_header->masterdatatable_offset);
2337 
2338 	if (!bp->master_data_tbl)
2339 		return false;
2340 
2341 	bp->object_info_tbl_offset = DATA_TABLES(displayobjectinfo);
2342 
2343 	if (!bp->object_info_tbl_offset)
2344 		return false;
2345 
2346 	object_info_tbl =
2347 			GET_IMAGE(struct display_object_info_table_v1_4,
2348 						bp->object_info_tbl_offset);
2349 
2350 	if (!object_info_tbl)
2351 		return false;
2352 
2353 	get_atom_data_table_revision(&object_info_tbl->table_header,
2354 		&bp->object_info_tbl.revision);
2355 
2356 	if (bp->object_info_tbl.revision.major == 1
2357 		&& bp->object_info_tbl.revision.minor >= 4) {
2358 		struct display_object_info_table_v1_4 *tbl_v1_4;
2359 
2360 		tbl_v1_4 = GET_IMAGE(struct display_object_info_table_v1_4,
2361 			bp->object_info_tbl_offset);
2362 		if (!tbl_v1_4)
2363 			return false;
2364 
2365 		bp->object_info_tbl.v1_4 = tbl_v1_4;
2366 	} else
2367 		return false;
2368 
2369 	dal_firmware_parser_init_cmd_tbl(bp);
2370 	dal_bios_parser_init_cmd_tbl_helper2(&bp->cmd_helper, dce_version);
2371 
2372 	bp->base.integrated_info = bios_parser_create_integrated_info(&bp->base);
2373 	bp->base.fw_info_valid = bios_parser_get_firmware_info(&bp->base, &bp->base.fw_info) == BP_RESULT_OK;
2374 	bios_parser_get_vram_info(&bp->base, &bp->base.vram_info);
2375 
2376 	return true;
2377 }
2378 
firmware_parser_create(struct bp_init_data * init,enum dce_version dce_version)2379 struct dc_bios *firmware_parser_create(
2380 	struct bp_init_data *init,
2381 	enum dce_version dce_version)
2382 {
2383 	struct bios_parser *bp = NULL;
2384 
2385 	bp = kzalloc(sizeof(struct bios_parser), GFP_KERNEL);
2386 	if (!bp)
2387 		return NULL;
2388 
2389 	if (bios_parser2_construct(bp, init, dce_version))
2390 		return &bp->base;
2391 
2392 	kfree(bp);
2393 	return NULL;
2394 }
2395 
2396 
2397