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