2 * Copyright 2012-15 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include "dm_services.h"
29 #include "atomfirmware.h"
31 #include "dc_bios_types.h"
32 #include "include/grph_object_ctrl_defs.h"
33 #include "include/bios_parser_interface.h"
34 #include "include/i2caux_interface.h"
35 #include "include/logger_interface.h"
37 #include "command_table2.h"
39 #include "bios_parser_helper.h"
40 #include "command_table_helper2.h"
41 #include "bios_parser2.h"
42 #include "bios_parser_types_internal2.h"
43 #include "bios_parser_interface.h"
45 #include "bios_parser_common.h"
47 /* Temporarily add in defines until ObjectID.h patch is updated in a few days */
48 #ifndef GENERIC_OBJECT_ID_BRACKET_LAYOUT
49 #define GENERIC_OBJECT_ID_BRACKET_LAYOUT 0x05
50 #endif /* GENERIC_OBJECT_ID_BRACKET_LAYOUT */
52 #ifndef GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID1
53 #define GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID1 \
54 (GRAPH_OBJECT_TYPE_GENERIC << OBJECT_TYPE_SHIFT |\
55 GRAPH_OBJECT_ENUM_ID1 << ENUM_ID_SHIFT |\
56 GENERIC_OBJECT_ID_BRACKET_LAYOUT << OBJECT_ID_SHIFT)
57 #endif /* GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID1 */
59 #ifndef GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID2
60 #define GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID2 \
61 (GRAPH_OBJECT_TYPE_GENERIC << OBJECT_TYPE_SHIFT |\
62 GRAPH_OBJECT_ENUM_ID2 << ENUM_ID_SHIFT |\
63 GENERIC_OBJECT_ID_BRACKET_LAYOUT << OBJECT_ID_SHIFT)
64 #endif /* GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID2 */
69 #define LAST_RECORD_TYPE 0xff
70 #define SMU9_SYSPLL0_ID 0
72 struct i2c_id_config_access {
73 uint8_t bfI2C_LineMux:4;
74 uint8_t bfHW_EngineID:3;
75 uint8_t bfHW_Capable:1;
79 static enum bp_result get_gpio_i2c_info(struct bios_parser *bp,
80 struct atom_i2c_record *record,
81 struct graphics_object_i2c_info *info);
83 static enum bp_result bios_parser_get_firmware_info(
85 struct dc_firmware_info *info);
87 static enum bp_result bios_parser_get_encoder_cap_info(
89 struct graphics_object_id object_id,
90 struct bp_encoder_cap_info *info);
92 static enum bp_result get_firmware_info_v3_1(
93 struct bios_parser *bp,
94 struct dc_firmware_info *info);
96 static enum bp_result get_firmware_info_v3_2(
97 struct bios_parser *bp,
98 struct dc_firmware_info *info);
100 static struct atom_hpd_int_record *get_hpd_record(struct bios_parser *bp,
101 struct atom_display_object_path_v2 *object);
103 static struct atom_encoder_caps_record *get_encoder_cap_record(
104 struct bios_parser *bp,
105 struct atom_display_object_path_v2 *object);
107 #define BIOS_IMAGE_SIZE_OFFSET 2
108 #define BIOS_IMAGE_SIZE_UNIT 512
110 #define DATA_TABLES(table) (bp->master_data_tbl->listOfdatatables.table)
112 static void destruct(struct bios_parser *bp)
114 kfree(bp->base.bios_local_image);
115 kfree(bp->base.integrated_info);
118 static void firmware_parser_destroy(struct dc_bios **dcb)
120 struct bios_parser *bp = BP_FROM_DCB(*dcb);
133 static void get_atom_data_table_revision(
134 struct atom_common_table_header *atom_data_tbl,
135 struct atom_data_revision *tbl_revision)
140 /* initialize the revision to 0 which is invalid revision */
141 tbl_revision->major = 0;
142 tbl_revision->minor = 0;
147 tbl_revision->major =
148 (uint32_t) atom_data_tbl->format_revision & 0x3f;
149 tbl_revision->minor =
150 (uint32_t) atom_data_tbl->content_revision & 0x3f;
153 /* BIOS oject table displaypath is per connector.
154 * There is extra path not for connector. BIOS fill its encoderid as 0
156 static uint8_t bios_parser_get_connectors_number(struct dc_bios *dcb)
158 struct bios_parser *bp = BP_FROM_DCB(dcb);
159 unsigned int count = 0;
162 for (i = 0; i < bp->object_info_tbl.v1_4->number_of_path; i++) {
163 if (bp->object_info_tbl.v1_4->display_path[i].encoderobjid != 0)
169 static struct graphics_object_id bios_parser_get_connector_id(
173 struct bios_parser *bp = BP_FROM_DCB(dcb);
174 struct graphics_object_id object_id = dal_graphics_object_id_init(
175 0, ENUM_ID_UNKNOWN, OBJECT_TYPE_UNKNOWN);
176 struct object_info_table *tbl = &bp->object_info_tbl;
177 struct display_object_info_table_v1_4 *v1_4 = tbl->v1_4;
179 if (v1_4->number_of_path > i) {
180 /* If display_objid is generic object id, the encoderObj
181 * /extencoderobjId should be 0
183 if (v1_4->display_path[i].encoderobjid != 0 &&
184 v1_4->display_path[i].display_objid != 0)
185 object_id = object_id_from_bios_object_id(
186 v1_4->display_path[i].display_objid);
192 static enum bp_result bios_parser_get_src_obj(struct dc_bios *dcb,
193 struct graphics_object_id object_id, uint32_t index,
194 struct graphics_object_id *src_object_id)
196 struct bios_parser *bp = BP_FROM_DCB(dcb);
198 enum bp_result bp_result = BP_RESULT_BADINPUT;
199 struct graphics_object_id obj_id = {0};
200 struct object_info_table *tbl = &bp->object_info_tbl;
205 switch (object_id.type) {
206 /* Encoder's Source is GPU. BIOS does not provide GPU, since all
207 * displaypaths point to same GPU (0x1100). Hardcode GPU object type
209 case OBJECT_TYPE_ENCODER:
210 /* TODO: since num of src must be less than 2.
211 * If found in for loop, should break.
212 * DAL2 implementation may be changed too
214 for (i = 0; i < tbl->v1_4->number_of_path; i++) {
215 obj_id = object_id_from_bios_object_id(
216 tbl->v1_4->display_path[i].encoderobjid);
217 if (object_id.type == obj_id.type &&
218 object_id.id == obj_id.id &&
222 object_id_from_bios_object_id(0x1100);
226 bp_result = BP_RESULT_OK;
228 case OBJECT_TYPE_CONNECTOR:
229 for (i = 0; i < tbl->v1_4->number_of_path; i++) {
230 obj_id = object_id_from_bios_object_id(
231 tbl->v1_4->display_path[i].display_objid);
233 if (object_id.type == obj_id.type &&
234 object_id.id == obj_id.id &&
235 object_id.enum_id == obj_id.enum_id) {
237 object_id_from_bios_object_id(
238 tbl->v1_4->display_path[i].encoderobjid);
242 bp_result = BP_RESULT_OK;
251 /* from graphics_object_id, find display path which includes the object_id */
252 static struct atom_display_object_path_v2 *get_bios_object(
253 struct bios_parser *bp,
254 struct graphics_object_id id)
257 struct graphics_object_id obj_id = {0};
260 case OBJECT_TYPE_ENCODER:
261 for (i = 0; i < bp->object_info_tbl.v1_4->number_of_path; i++) {
262 obj_id = object_id_from_bios_object_id(
263 bp->object_info_tbl.v1_4->display_path[i].encoderobjid);
264 if (id.type == obj_id.type && id.id == obj_id.id
265 && id.enum_id == obj_id.enum_id)
266 return &bp->object_info_tbl.v1_4->display_path[i];
268 case OBJECT_TYPE_CONNECTOR:
269 case OBJECT_TYPE_GENERIC:
270 /* Both Generic and Connector Object ID
271 * will be stored on display_objid
273 for (i = 0; i < bp->object_info_tbl.v1_4->number_of_path; i++) {
274 obj_id = object_id_from_bios_object_id(
275 bp->object_info_tbl.v1_4->display_path[i].display_objid);
276 if (id.type == obj_id.type && id.id == obj_id.id
277 && id.enum_id == obj_id.enum_id)
278 return &bp->object_info_tbl.v1_4->display_path[i];
285 static enum bp_result bios_parser_get_i2c_info(struct dc_bios *dcb,
286 struct graphics_object_id id,
287 struct graphics_object_i2c_info *info)
290 struct atom_display_object_path_v2 *object;
291 struct atom_common_record_header *header;
292 struct atom_i2c_record *record;
293 struct bios_parser *bp = BP_FROM_DCB(dcb);
296 return BP_RESULT_BADINPUT;
298 object = get_bios_object(bp, id);
301 return BP_RESULT_BADINPUT;
303 offset = object->disp_recordoffset + bp->object_info_tbl_offset;
306 header = GET_IMAGE(struct atom_common_record_header, offset);
309 return BP_RESULT_BADBIOSTABLE;
311 if (header->record_type == LAST_RECORD_TYPE ||
312 !header->record_size)
315 if (header->record_type == ATOM_I2C_RECORD_TYPE
316 && sizeof(struct atom_i2c_record) <=
317 header->record_size) {
318 /* get the I2C info */
319 record = (struct atom_i2c_record *) header;
321 if (get_gpio_i2c_info(bp, record, info) ==
326 offset += header->record_size;
329 return BP_RESULT_NORECORD;
332 static enum bp_result get_gpio_i2c_info(
333 struct bios_parser *bp,
334 struct atom_i2c_record *record,
335 struct graphics_object_i2c_info *info)
337 struct atom_gpio_pin_lut_v2_1 *header;
339 unsigned int table_index = 0;
342 return BP_RESULT_BADINPUT;
344 /* get the GPIO_I2C info */
345 if (!DATA_TABLES(gpio_pin_lut))
346 return BP_RESULT_BADBIOSTABLE;
348 header = GET_IMAGE(struct atom_gpio_pin_lut_v2_1,
349 DATA_TABLES(gpio_pin_lut));
351 return BP_RESULT_BADBIOSTABLE;
353 if (sizeof(struct atom_common_table_header) +
354 sizeof(struct atom_gpio_pin_assignment) >
355 le16_to_cpu(header->table_header.structuresize))
356 return BP_RESULT_BADBIOSTABLE;
358 /* TODO: is version change? */
359 if (header->table_header.content_revision != 1)
360 return BP_RESULT_UNSUPPORTED;
363 count = (le16_to_cpu(header->table_header.structuresize)
364 - sizeof(struct atom_common_table_header))
365 / sizeof(struct atom_gpio_pin_assignment);
367 table_index = record->i2c_id & I2C_HW_LANE_MUX;
369 if (count < table_index) {
370 bool find_valid = false;
372 for (table_index = 0; table_index < count; table_index++) {
373 if (((record->i2c_id & I2C_HW_CAP) == (
374 header->gpio_pin[table_index].gpio_id &
376 ((record->i2c_id & I2C_HW_ENGINE_ID_MASK) ==
377 (header->gpio_pin[table_index].gpio_id &
378 I2C_HW_ENGINE_ID_MASK)) &&
379 ((record->i2c_id & I2C_HW_LANE_MUX) ==
380 (header->gpio_pin[table_index].gpio_id &
387 /* If we don't find the entry that we are looking for then
388 * we will return BP_Result_BadBiosTable.
390 if (find_valid == false)
391 return BP_RESULT_BADBIOSTABLE;
394 /* get the GPIO_I2C_INFO */
395 info->i2c_hw_assist = (record->i2c_id & I2C_HW_CAP) ? true : false;
396 info->i2c_line = record->i2c_id & I2C_HW_LANE_MUX;
397 info->i2c_engine_id = (record->i2c_id & I2C_HW_ENGINE_ID_MASK) >> 4;
398 info->i2c_slave_address = record->i2c_slave_addr;
400 /* TODO: check how to get register offset for en, Y, etc. */
401 info->gpio_info.clk_a_register_index =
403 header->gpio_pin[table_index].data_a_reg_index);
404 info->gpio_info.clk_a_shift =
405 header->gpio_pin[table_index].gpio_bitshift;
410 static enum bp_result bios_parser_get_hpd_info(
412 struct graphics_object_id id,
413 struct graphics_object_hpd_info *info)
415 struct bios_parser *bp = BP_FROM_DCB(dcb);
416 struct atom_display_object_path_v2 *object;
417 struct atom_hpd_int_record *record = NULL;
420 return BP_RESULT_BADINPUT;
422 object = get_bios_object(bp, id);
425 return BP_RESULT_BADINPUT;
427 record = get_hpd_record(bp, object);
429 if (record != NULL) {
430 info->hpd_int_gpio_uid = record->pin_id;
431 info->hpd_active = record->plugin_pin_state;
435 return BP_RESULT_NORECORD;
438 static struct atom_hpd_int_record *get_hpd_record(
439 struct bios_parser *bp,
440 struct atom_display_object_path_v2 *object)
442 struct atom_common_record_header *header;
446 BREAK_TO_DEBUGGER(); /* Invalid object */
450 offset = le16_to_cpu(object->disp_recordoffset)
451 + bp->object_info_tbl_offset;
454 header = GET_IMAGE(struct atom_common_record_header, offset);
459 if (header->record_type == LAST_RECORD_TYPE ||
460 !header->record_size)
463 if (header->record_type == ATOM_HPD_INT_RECORD_TYPE
464 && sizeof(struct atom_hpd_int_record) <=
466 return (struct atom_hpd_int_record *) header;
468 offset += header->record_size;
475 * bios_parser_get_gpio_pin_info
476 * Get GpioPin information of input gpio id
478 * @param gpio_id, GPIO ID
479 * @param info, GpioPin information structure
480 * @return Bios parser result code
482 * to get the GPIO PIN INFO, we need:
483 * 1. get the GPIO_ID from other object table, see GetHPDInfo()
484 * 2. in DATA_TABLE.GPIO_Pin_LUT, search all records,
485 * to get the registerA offset/mask
487 static enum bp_result bios_parser_get_gpio_pin_info(
490 struct gpio_pin_info *info)
492 struct bios_parser *bp = BP_FROM_DCB(dcb);
493 struct atom_gpio_pin_lut_v2_1 *header;
497 if (!DATA_TABLES(gpio_pin_lut))
498 return BP_RESULT_BADBIOSTABLE;
500 header = GET_IMAGE(struct atom_gpio_pin_lut_v2_1,
501 DATA_TABLES(gpio_pin_lut));
503 return BP_RESULT_BADBIOSTABLE;
505 if (sizeof(struct atom_common_table_header) +
506 sizeof(struct atom_gpio_pin_assignment)
507 > le16_to_cpu(header->table_header.structuresize))
508 return BP_RESULT_BADBIOSTABLE;
510 if (header->table_header.content_revision != 1)
511 return BP_RESULT_UNSUPPORTED;
513 /* Temporary hard code gpio pin info */
514 #if defined(FOR_SIMNOW_BOOT)
516 struct atom_gpio_pin_assignment gpio_pin[8] = {
517 {0x5db5, 0, 0, 1, 0},
518 {0x5db5, 8, 8, 2, 0},
519 {0x5db5, 0x10, 0x10, 3, 0},
520 {0x5db5, 0x18, 0x14, 4, 0},
521 {0x5db5, 0x1A, 0x18, 5, 0},
522 {0x5db5, 0x1C, 0x1C, 6, 0},
526 memmove(header->gpio_pin, gpio_pin, sizeof(gpio_pin));
529 count = (le16_to_cpu(header->table_header.structuresize)
530 - sizeof(struct atom_common_table_header))
531 / sizeof(struct atom_gpio_pin_assignment);
533 for (i = 0; i < count; ++i) {
534 if (header->gpio_pin[i].gpio_id != gpio_id)
538 (uint32_t) le16_to_cpu(
539 header->gpio_pin[i].data_a_reg_index);
540 info->offset_y = info->offset + 2;
541 info->offset_en = info->offset + 1;
542 info->offset_mask = info->offset - 1;
544 info->mask = (uint32_t) (1 <<
545 header->gpio_pin[i].gpio_bitshift);
546 info->mask_y = info->mask + 2;
547 info->mask_en = info->mask + 1;
548 info->mask_mask = info->mask - 1;
553 return BP_RESULT_NORECORD;
556 static struct device_id device_type_from_device_id(uint16_t device_id)
559 struct device_id result_device_id;
561 result_device_id.raw_device_tag = device_id;
564 case ATOM_DISPLAY_LCD1_SUPPORT:
565 result_device_id.device_type = DEVICE_TYPE_LCD;
566 result_device_id.enum_id = 1;
569 case ATOM_DISPLAY_DFP1_SUPPORT:
570 result_device_id.device_type = DEVICE_TYPE_DFP;
571 result_device_id.enum_id = 1;
574 case ATOM_DISPLAY_DFP2_SUPPORT:
575 result_device_id.device_type = DEVICE_TYPE_DFP;
576 result_device_id.enum_id = 2;
579 case ATOM_DISPLAY_DFP3_SUPPORT:
580 result_device_id.device_type = DEVICE_TYPE_DFP;
581 result_device_id.enum_id = 3;
584 case ATOM_DISPLAY_DFP4_SUPPORT:
585 result_device_id.device_type = DEVICE_TYPE_DFP;
586 result_device_id.enum_id = 4;
589 case ATOM_DISPLAY_DFP5_SUPPORT:
590 result_device_id.device_type = DEVICE_TYPE_DFP;
591 result_device_id.enum_id = 5;
594 case ATOM_DISPLAY_DFP6_SUPPORT:
595 result_device_id.device_type = DEVICE_TYPE_DFP;
596 result_device_id.enum_id = 6;
600 BREAK_TO_DEBUGGER(); /* Invalid device Id */
601 result_device_id.device_type = DEVICE_TYPE_UNKNOWN;
602 result_device_id.enum_id = 0;
604 return result_device_id;
607 static enum bp_result bios_parser_get_device_tag(
609 struct graphics_object_id connector_object_id,
610 uint32_t device_tag_index,
611 struct connector_device_tag_info *info)
613 struct bios_parser *bp = BP_FROM_DCB(dcb);
614 struct atom_display_object_path_v2 *object;
617 return BP_RESULT_BADINPUT;
619 /* getBiosObject will return MXM object */
620 object = get_bios_object(bp, connector_object_id);
623 BREAK_TO_DEBUGGER(); /* Invalid object id */
624 return BP_RESULT_BADINPUT;
627 info->acpi_device = 0; /* BIOS no longer provides this */
628 info->dev_id = device_type_from_device_id(object->device_tag);
633 static enum bp_result get_ss_info_v4_1(
634 struct bios_parser *bp,
637 struct spread_spectrum_info *ss_info)
639 enum bp_result result = BP_RESULT_OK;
640 struct atom_display_controller_info_v4_1 *disp_cntl_tbl = NULL;
641 struct atom_smu_info_v3_3 *smu_info = NULL;
644 return BP_RESULT_BADINPUT;
646 if (!DATA_TABLES(dce_info))
647 return BP_RESULT_BADBIOSTABLE;
649 disp_cntl_tbl = GET_IMAGE(struct atom_display_controller_info_v4_1,
650 DATA_TABLES(dce_info));
652 return BP_RESULT_BADBIOSTABLE;
655 ss_info->type.STEP_AND_DELAY_INFO = false;
656 ss_info->spread_percentage_divider = 1000;
657 /* BIOS no longer uses target clock. Always enable for now */
658 ss_info->target_clock_range = 0xffffffff;
661 case AS_SIGNAL_TYPE_DVI:
662 ss_info->spread_spectrum_percentage =
663 disp_cntl_tbl->dvi_ss_percentage;
664 ss_info->spread_spectrum_range =
665 disp_cntl_tbl->dvi_ss_rate_10hz * 10;
666 if (disp_cntl_tbl->dvi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
667 ss_info->type.CENTER_MODE = true;
669 case AS_SIGNAL_TYPE_HDMI:
670 ss_info->spread_spectrum_percentage =
671 disp_cntl_tbl->hdmi_ss_percentage;
672 ss_info->spread_spectrum_range =
673 disp_cntl_tbl->hdmi_ss_rate_10hz * 10;
674 if (disp_cntl_tbl->hdmi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
675 ss_info->type.CENTER_MODE = true;
677 /* TODO LVDS not support anymore? */
678 case AS_SIGNAL_TYPE_DISPLAY_PORT:
679 ss_info->spread_spectrum_percentage =
680 disp_cntl_tbl->dp_ss_percentage;
681 ss_info->spread_spectrum_range =
682 disp_cntl_tbl->dp_ss_rate_10hz * 10;
683 if (disp_cntl_tbl->dp_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
684 ss_info->type.CENTER_MODE = true;
686 case AS_SIGNAL_TYPE_GPU_PLL:
687 /* atom_firmware: DAL only get data from dce_info table.
688 * if data within smu_info is needed for DAL, VBIOS should
689 * copy it into dce_info
691 result = BP_RESULT_UNSUPPORTED;
693 case AS_SIGNAL_TYPE_XGMI:
694 smu_info = GET_IMAGE(struct atom_smu_info_v3_3,
695 DATA_TABLES(smu_info));
697 return BP_RESULT_BADBIOSTABLE;
699 ss_info->spread_spectrum_percentage =
700 smu_info->waflclk_ss_percentage;
701 ss_info->spread_spectrum_range =
702 smu_info->gpuclk_ss_rate_10hz * 10;
703 if (smu_info->waflclk_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
704 ss_info->type.CENTER_MODE = true;
707 result = BP_RESULT_UNSUPPORTED;
713 static enum bp_result get_ss_info_v4_2(
714 struct bios_parser *bp,
717 struct spread_spectrum_info *ss_info)
719 enum bp_result result = BP_RESULT_OK;
720 struct atom_display_controller_info_v4_2 *disp_cntl_tbl = NULL;
721 struct atom_smu_info_v3_1 *smu_info = NULL;
724 return BP_RESULT_BADINPUT;
726 if (!DATA_TABLES(dce_info))
727 return BP_RESULT_BADBIOSTABLE;
729 if (!DATA_TABLES(smu_info))
730 return BP_RESULT_BADBIOSTABLE;
732 disp_cntl_tbl = GET_IMAGE(struct atom_display_controller_info_v4_2,
733 DATA_TABLES(dce_info));
735 return BP_RESULT_BADBIOSTABLE;
737 smu_info = GET_IMAGE(struct atom_smu_info_v3_1, DATA_TABLES(smu_info));
739 return BP_RESULT_BADBIOSTABLE;
741 ss_info->type.STEP_AND_DELAY_INFO = false;
742 ss_info->spread_percentage_divider = 1000;
743 /* BIOS no longer uses target clock. Always enable for now */
744 ss_info->target_clock_range = 0xffffffff;
747 case AS_SIGNAL_TYPE_DVI:
748 ss_info->spread_spectrum_percentage =
749 disp_cntl_tbl->dvi_ss_percentage;
750 ss_info->spread_spectrum_range =
751 disp_cntl_tbl->dvi_ss_rate_10hz * 10;
752 if (disp_cntl_tbl->dvi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
753 ss_info->type.CENTER_MODE = true;
755 case AS_SIGNAL_TYPE_HDMI:
756 ss_info->spread_spectrum_percentage =
757 disp_cntl_tbl->hdmi_ss_percentage;
758 ss_info->spread_spectrum_range =
759 disp_cntl_tbl->hdmi_ss_rate_10hz * 10;
760 if (disp_cntl_tbl->hdmi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
761 ss_info->type.CENTER_MODE = true;
763 /* TODO LVDS not support anymore? */
764 case AS_SIGNAL_TYPE_DISPLAY_PORT:
765 ss_info->spread_spectrum_percentage =
766 smu_info->gpuclk_ss_percentage;
767 ss_info->spread_spectrum_range =
768 smu_info->gpuclk_ss_rate_10hz * 10;
769 if (smu_info->gpuclk_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
770 ss_info->type.CENTER_MODE = true;
772 case AS_SIGNAL_TYPE_GPU_PLL:
773 /* atom_firmware: DAL only get data from dce_info table.
774 * if data within smu_info is needed for DAL, VBIOS should
775 * copy it into dce_info
777 result = BP_RESULT_UNSUPPORTED;
780 result = BP_RESULT_UNSUPPORTED;
787 * bios_parser_get_spread_spectrum_info
788 * Get spread spectrum information from the ASIC_InternalSS_Info(ver 2.1 or
789 * ver 3.1) or SS_Info table from the VBIOS. Currently ASIC_InternalSS_Info
790 * ver 2.1 can co-exist with SS_Info table. Expect ASIC_InternalSS_Info
792 * there is only one entry for each signal /ss id. However, there is
793 * no planning of supporting multiple spread Sprectum entry for EverGreen
795 * @param [in] signal, ASSignalType to be converted to info index
796 * @param [in] index, number of entries that match the converted info index
797 * @param [out] ss_info, sprectrum information structure,
798 * @return Bios parser result code
800 static enum bp_result bios_parser_get_spread_spectrum_info(
802 enum as_signal_type signal,
804 struct spread_spectrum_info *ss_info)
806 struct bios_parser *bp = BP_FROM_DCB(dcb);
807 enum bp_result result = BP_RESULT_UNSUPPORTED;
808 struct atom_common_table_header *header;
809 struct atom_data_revision tbl_revision;
811 if (!ss_info) /* check for bad input */
812 return BP_RESULT_BADINPUT;
814 if (!DATA_TABLES(dce_info))
815 return BP_RESULT_UNSUPPORTED;
817 header = GET_IMAGE(struct atom_common_table_header,
818 DATA_TABLES(dce_info));
819 get_atom_data_table_revision(header, &tbl_revision);
821 switch (tbl_revision.major) {
823 switch (tbl_revision.minor) {
825 return get_ss_info_v4_1(bp, signal, index, ss_info);
827 return get_ss_info_v4_2(bp, signal, index, ss_info);
835 /* there can not be more then one entry for SS Info table */
839 static enum bp_result get_embedded_panel_info_v2_1(
840 struct bios_parser *bp,
841 struct embedded_panel_info *info)
843 struct lcd_info_v2_1 *lvds;
846 return BP_RESULT_BADINPUT;
848 if (!DATA_TABLES(lcd_info))
849 return BP_RESULT_UNSUPPORTED;
851 lvds = GET_IMAGE(struct lcd_info_v2_1, DATA_TABLES(lcd_info));
854 return BP_RESULT_BADBIOSTABLE;
856 /* TODO: previous vv1_3, should v2_1 */
857 if (!((lvds->table_header.format_revision == 2)
858 && (lvds->table_header.content_revision >= 1)))
859 return BP_RESULT_UNSUPPORTED;
861 memset(info, 0, sizeof(struct embedded_panel_info));
863 /* We need to convert from 10KHz units into KHz units */
864 info->lcd_timing.pixel_clk = le16_to_cpu(lvds->lcd_timing.pixclk) * 10;
865 /* usHActive does not include borders, according to VBIOS team */
866 info->lcd_timing.horizontal_addressable = le16_to_cpu(lvds->lcd_timing.h_active);
867 /* usHBlanking_Time includes borders, so we should really be
868 * subtractingborders duing this translation, but LVDS generally
869 * doesn't have borders, so we should be okay leaving this as is for
870 * now. May need to revisit if we ever have LVDS with borders
872 info->lcd_timing.horizontal_blanking_time = le16_to_cpu(lvds->lcd_timing.h_blanking_time);
873 /* usVActive does not include borders, according to VBIOS team*/
874 info->lcd_timing.vertical_addressable = le16_to_cpu(lvds->lcd_timing.v_active);
875 /* usVBlanking_Time includes borders, so we should really be
876 * subtracting borders duing this translation, but LVDS generally
877 * doesn't have borders, so we should be okay leaving this as is for
878 * now. May need to revisit if we ever have LVDS with borders
880 info->lcd_timing.vertical_blanking_time = le16_to_cpu(lvds->lcd_timing.v_blanking_time);
881 info->lcd_timing.horizontal_sync_offset = le16_to_cpu(lvds->lcd_timing.h_sync_offset);
882 info->lcd_timing.horizontal_sync_width = le16_to_cpu(lvds->lcd_timing.h_sync_width);
883 info->lcd_timing.vertical_sync_offset = le16_to_cpu(lvds->lcd_timing.v_sync_offset);
884 info->lcd_timing.vertical_sync_width = le16_to_cpu(lvds->lcd_timing.v_syncwidth);
885 info->lcd_timing.horizontal_border = lvds->lcd_timing.h_border;
886 info->lcd_timing.vertical_border = lvds->lcd_timing.v_border;
888 /* not provided by VBIOS */
889 info->lcd_timing.misc_info.HORIZONTAL_CUT_OFF = 0;
891 info->lcd_timing.misc_info.H_SYNC_POLARITY = ~(uint32_t) (lvds->lcd_timing.miscinfo
892 & ATOM_HSYNC_POLARITY);
893 info->lcd_timing.misc_info.V_SYNC_POLARITY = ~(uint32_t) (lvds->lcd_timing.miscinfo
894 & ATOM_VSYNC_POLARITY);
896 /* not provided by VBIOS */
897 info->lcd_timing.misc_info.VERTICAL_CUT_OFF = 0;
899 info->lcd_timing.misc_info.H_REPLICATION_BY2 = !!(lvds->lcd_timing.miscinfo
900 & ATOM_H_REPLICATIONBY2);
901 info->lcd_timing.misc_info.V_REPLICATION_BY2 = !!(lvds->lcd_timing.miscinfo
902 & ATOM_V_REPLICATIONBY2);
903 info->lcd_timing.misc_info.COMPOSITE_SYNC = !!(lvds->lcd_timing.miscinfo
904 & ATOM_COMPOSITESYNC);
905 info->lcd_timing.misc_info.INTERLACE = !!(lvds->lcd_timing.miscinfo & ATOM_INTERLACE);
907 /* not provided by VBIOS*/
908 info->lcd_timing.misc_info.DOUBLE_CLOCK = 0;
909 /* not provided by VBIOS*/
912 info->realtek_eDPToLVDS = !!(lvds->dplvdsrxid == eDP_TO_LVDS_REALTEK_ID);
917 static enum bp_result bios_parser_get_embedded_panel_info(
919 struct embedded_panel_info *info)
922 *bp = BP_FROM_DCB(dcb);
923 struct atom_common_table_header *header;
924 struct atom_data_revision tbl_revision;
926 if (!DATA_TABLES(lcd_info))
927 return BP_RESULT_FAILURE;
929 header = GET_IMAGE(struct atom_common_table_header, DATA_TABLES(lcd_info));
932 return BP_RESULT_BADBIOSTABLE;
934 get_atom_data_table_revision(header, &tbl_revision);
936 switch (tbl_revision.major) {
938 switch (tbl_revision.minor) {
940 return get_embedded_panel_info_v2_1(bp, info);
948 return BP_RESULT_FAILURE;
951 static uint32_t get_support_mask_for_device_id(struct device_id device_id)
953 enum dal_device_type device_type = device_id.device_type;
954 uint32_t enum_id = device_id.enum_id;
956 switch (device_type) {
957 case DEVICE_TYPE_LCD:
960 return ATOM_DISPLAY_LCD1_SUPPORT;
965 case DEVICE_TYPE_DFP:
968 return ATOM_DISPLAY_DFP1_SUPPORT;
970 return ATOM_DISPLAY_DFP2_SUPPORT;
972 return ATOM_DISPLAY_DFP3_SUPPORT;
974 return ATOM_DISPLAY_DFP4_SUPPORT;
976 return ATOM_DISPLAY_DFP5_SUPPORT;
978 return ATOM_DISPLAY_DFP6_SUPPORT;
987 /* Unidentified device ID, return empty support mask. */
991 static bool bios_parser_is_device_id_supported(
995 struct bios_parser *bp = BP_FROM_DCB(dcb);
997 uint32_t mask = get_support_mask_for_device_id(id);
999 return (le16_to_cpu(bp->object_info_tbl.v1_4->supporteddevices) &
1003 static uint32_t bios_parser_get_ss_entry_number(
1004 struct dc_bios *dcb,
1005 enum as_signal_type signal)
1007 /* TODO: DAL2 atomfirmware implementation does not need this.
1008 * why DAL3 need this?
1013 static enum bp_result bios_parser_transmitter_control(
1014 struct dc_bios *dcb,
1015 struct bp_transmitter_control *cntl)
1017 struct bios_parser *bp = BP_FROM_DCB(dcb);
1019 if (!bp->cmd_tbl.transmitter_control)
1020 return BP_RESULT_FAILURE;
1022 return bp->cmd_tbl.transmitter_control(bp, cntl);
1025 static enum bp_result bios_parser_encoder_control(
1026 struct dc_bios *dcb,
1027 struct bp_encoder_control *cntl)
1029 struct bios_parser *bp = BP_FROM_DCB(dcb);
1031 if (!bp->cmd_tbl.dig_encoder_control)
1032 return BP_RESULT_FAILURE;
1034 return bp->cmd_tbl.dig_encoder_control(bp, cntl);
1037 static enum bp_result bios_parser_set_pixel_clock(
1038 struct dc_bios *dcb,
1039 struct bp_pixel_clock_parameters *bp_params)
1041 struct bios_parser *bp = BP_FROM_DCB(dcb);
1043 if (!bp->cmd_tbl.set_pixel_clock)
1044 return BP_RESULT_FAILURE;
1046 return bp->cmd_tbl.set_pixel_clock(bp, bp_params);
1049 static enum bp_result bios_parser_set_dce_clock(
1050 struct dc_bios *dcb,
1051 struct bp_set_dce_clock_parameters *bp_params)
1053 struct bios_parser *bp = BP_FROM_DCB(dcb);
1055 if (!bp->cmd_tbl.set_dce_clock)
1056 return BP_RESULT_FAILURE;
1058 return bp->cmd_tbl.set_dce_clock(bp, bp_params);
1061 static enum bp_result bios_parser_program_crtc_timing(
1062 struct dc_bios *dcb,
1063 struct bp_hw_crtc_timing_parameters *bp_params)
1065 struct bios_parser *bp = BP_FROM_DCB(dcb);
1067 if (!bp->cmd_tbl.set_crtc_timing)
1068 return BP_RESULT_FAILURE;
1070 return bp->cmd_tbl.set_crtc_timing(bp, bp_params);
1073 static enum bp_result bios_parser_enable_crtc(
1074 struct dc_bios *dcb,
1075 enum controller_id id,
1078 struct bios_parser *bp = BP_FROM_DCB(dcb);
1080 if (!bp->cmd_tbl.enable_crtc)
1081 return BP_RESULT_FAILURE;
1083 return bp->cmd_tbl.enable_crtc(bp, id, enable);
1086 static enum bp_result bios_parser_enable_disp_power_gating(
1087 struct dc_bios *dcb,
1088 enum controller_id controller_id,
1089 enum bp_pipe_control_action action)
1091 struct bios_parser *bp = BP_FROM_DCB(dcb);
1093 if (!bp->cmd_tbl.enable_disp_power_gating)
1094 return BP_RESULT_FAILURE;
1096 return bp->cmd_tbl.enable_disp_power_gating(bp, controller_id,
1100 static bool bios_parser_is_accelerated_mode(
1101 struct dc_bios *dcb)
1103 return bios_is_accelerated_mode(dcb);
1107 * bios_parser_set_scratch_critical_state
1110 * update critical state bit in VBIOS scratch register
1113 * bool - to set or reset state
1115 static void bios_parser_set_scratch_critical_state(
1116 struct dc_bios *dcb,
1119 bios_set_scratch_critical_state(dcb, state);
1122 static enum bp_result bios_parser_get_firmware_info(
1123 struct dc_bios *dcb,
1124 struct dc_firmware_info *info)
1126 struct bios_parser *bp = BP_FROM_DCB(dcb);
1127 enum bp_result result = BP_RESULT_BADBIOSTABLE;
1128 struct atom_common_table_header *header;
1130 struct atom_data_revision revision;
1132 if (info && DATA_TABLES(firmwareinfo)) {
1133 header = GET_IMAGE(struct atom_common_table_header,
1134 DATA_TABLES(firmwareinfo));
1135 get_atom_data_table_revision(header, &revision);
1136 switch (revision.major) {
1138 switch (revision.minor) {
1140 result = get_firmware_info_v3_1(bp, info);
1143 result = get_firmware_info_v3_2(bp, info);
1146 result = get_firmware_info_v3_2(bp, info);
1160 static enum bp_result get_firmware_info_v3_1(
1161 struct bios_parser *bp,
1162 struct dc_firmware_info *info)
1164 struct atom_firmware_info_v3_1 *firmware_info;
1165 struct atom_display_controller_info_v4_1 *dce_info = NULL;
1168 return BP_RESULT_BADINPUT;
1170 firmware_info = GET_IMAGE(struct atom_firmware_info_v3_1,
1171 DATA_TABLES(firmwareinfo));
1173 dce_info = GET_IMAGE(struct atom_display_controller_info_v4_1,
1174 DATA_TABLES(dce_info));
1176 if (!firmware_info || !dce_info)
1177 return BP_RESULT_BADBIOSTABLE;
1179 memset(info, 0, sizeof(*info));
1181 /* Pixel clock pll information. */
1182 /* We need to convert from 10KHz units into KHz units */
1183 info->default_memory_clk = firmware_info->bootup_mclk_in10khz * 10;
1184 info->default_engine_clk = firmware_info->bootup_sclk_in10khz * 10;
1186 /* 27MHz for Vega10: */
1187 info->pll_info.crystal_frequency = dce_info->dce_refclk_10khz * 10;
1189 /* Hardcode frequency if BIOS gives no DCE Ref Clk */
1190 if (info->pll_info.crystal_frequency == 0)
1191 info->pll_info.crystal_frequency = 27000;
1192 /*dp_phy_ref_clk is not correct for atom_display_controller_info_v4_2, but we don't use it*/
1193 info->dp_phy_ref_clk = dce_info->dpphy_refclk_10khz * 10;
1194 info->i2c_engine_ref_clk = dce_info->i2c_engine_refclk_10khz * 10;
1196 /* Get GPU PLL VCO Clock */
1198 if (bp->cmd_tbl.get_smu_clock_info != NULL) {
1199 /* VBIOS gives in 10KHz */
1200 info->smu_gpu_pll_output_freq =
1201 bp->cmd_tbl.get_smu_clock_info(bp, SMU9_SYSPLL0_ID) * 10;
1204 return BP_RESULT_OK;
1207 static enum bp_result get_firmware_info_v3_2(
1208 struct bios_parser *bp,
1209 struct dc_firmware_info *info)
1211 struct atom_firmware_info_v3_2 *firmware_info;
1212 struct atom_display_controller_info_v4_1 *dce_info = NULL;
1213 struct atom_common_table_header *header;
1214 struct atom_data_revision revision;
1215 struct atom_smu_info_v3_2 *smu_info_v3_2 = NULL;
1216 struct atom_smu_info_v3_3 *smu_info_v3_3 = NULL;
1219 return BP_RESULT_BADINPUT;
1221 firmware_info = GET_IMAGE(struct atom_firmware_info_v3_2,
1222 DATA_TABLES(firmwareinfo));
1224 dce_info = GET_IMAGE(struct atom_display_controller_info_v4_1,
1225 DATA_TABLES(dce_info));
1227 if (!firmware_info || !dce_info)
1228 return BP_RESULT_BADBIOSTABLE;
1230 memset(info, 0, sizeof(*info));
1232 header = GET_IMAGE(struct atom_common_table_header,
1233 DATA_TABLES(smu_info));
1234 get_atom_data_table_revision(header, &revision);
1236 if (revision.minor == 2) {
1238 smu_info_v3_2 = GET_IMAGE(struct atom_smu_info_v3_2,
1239 DATA_TABLES(smu_info));
1242 return BP_RESULT_BADBIOSTABLE;
1244 info->default_engine_clk = smu_info_v3_2->bootup_dcefclk_10khz * 10;
1245 } else if (revision.minor == 3) {
1247 smu_info_v3_3 = GET_IMAGE(struct atom_smu_info_v3_3,
1248 DATA_TABLES(smu_info));
1251 return BP_RESULT_BADBIOSTABLE;
1253 info->default_engine_clk = smu_info_v3_3->bootup_dcefclk_10khz * 10;
1256 // We need to convert from 10KHz units into KHz units.
1257 info->default_memory_clk = firmware_info->bootup_mclk_in10khz * 10;
1259 /* 27MHz for Vega10 & Vega12; 100MHz for Vega20 */
1260 info->pll_info.crystal_frequency = dce_info->dce_refclk_10khz * 10;
1261 /* Hardcode frequency if BIOS gives no DCE Ref Clk */
1262 if (info->pll_info.crystal_frequency == 0) {
1263 if (revision.minor == 2)
1264 info->pll_info.crystal_frequency = 27000;
1265 else if (revision.minor == 3)
1266 info->pll_info.crystal_frequency = 100000;
1268 /*dp_phy_ref_clk is not correct for atom_display_controller_info_v4_2, but we don't use it*/
1269 info->dp_phy_ref_clk = dce_info->dpphy_refclk_10khz * 10;
1270 info->i2c_engine_ref_clk = dce_info->i2c_engine_refclk_10khz * 10;
1272 /* Get GPU PLL VCO Clock */
1273 if (bp->cmd_tbl.get_smu_clock_info != NULL) {
1274 if (revision.minor == 2)
1275 info->smu_gpu_pll_output_freq =
1276 bp->cmd_tbl.get_smu_clock_info(bp, SMU9_SYSPLL0_ID) * 10;
1277 else if (revision.minor == 3)
1278 info->smu_gpu_pll_output_freq =
1279 bp->cmd_tbl.get_smu_clock_info(bp, SMU11_SYSPLL3_0_ID) * 10;
1282 return BP_RESULT_OK;
1285 static enum bp_result bios_parser_get_encoder_cap_info(
1286 struct dc_bios *dcb,
1287 struct graphics_object_id object_id,
1288 struct bp_encoder_cap_info *info)
1290 struct bios_parser *bp = BP_FROM_DCB(dcb);
1291 struct atom_display_object_path_v2 *object;
1292 struct atom_encoder_caps_record *record = NULL;
1295 return BP_RESULT_BADINPUT;
1297 object = get_bios_object(bp, object_id);
1300 return BP_RESULT_BADINPUT;
1302 record = get_encoder_cap_record(bp, object);
1304 return BP_RESULT_NORECORD;
1306 info->DP_HBR2_CAP = (record->encodercaps &
1307 ATOM_ENCODER_CAP_RECORD_HBR2) ? 1 : 0;
1308 info->DP_HBR2_EN = (record->encodercaps &
1309 ATOM_ENCODER_CAP_RECORD_HBR2_EN) ? 1 : 0;
1310 info->DP_HBR3_EN = (record->encodercaps &
1311 ATOM_ENCODER_CAP_RECORD_HBR3_EN) ? 1 : 0;
1312 info->HDMI_6GB_EN = (record->encodercaps &
1313 ATOM_ENCODER_CAP_RECORD_HDMI6Gbps_EN) ? 1 : 0;
1315 return BP_RESULT_OK;
1319 static struct atom_encoder_caps_record *get_encoder_cap_record(
1320 struct bios_parser *bp,
1321 struct atom_display_object_path_v2 *object)
1323 struct atom_common_record_header *header;
1327 BREAK_TO_DEBUGGER(); /* Invalid object */
1331 offset = object->encoder_recordoffset + bp->object_info_tbl_offset;
1334 header = GET_IMAGE(struct atom_common_record_header, offset);
1339 offset += header->record_size;
1341 if (header->record_type == LAST_RECORD_TYPE ||
1342 !header->record_size)
1345 if (header->record_type != ATOM_ENCODER_CAP_RECORD_TYPE)
1348 if (sizeof(struct atom_encoder_caps_record) <=
1349 header->record_size)
1350 return (struct atom_encoder_caps_record *)header;
1357 * get_integrated_info_v11
1360 * Get V8 integrated BIOS information
1363 * bios_parser *bp - [in]BIOS parser handler to get master data table
1364 * integrated_info *info - [out] store and output integrated info
1367 * enum bp_result - BP_RESULT_OK if information is available,
1368 * BP_RESULT_BADBIOSTABLE otherwise.
1370 static enum bp_result get_integrated_info_v11(
1371 struct bios_parser *bp,
1372 struct integrated_info *info)
1374 struct atom_integrated_system_info_v1_11 *info_v11;
1377 info_v11 = GET_IMAGE(struct atom_integrated_system_info_v1_11,
1378 DATA_TABLES(integratedsysteminfo));
1380 if (info_v11 == NULL)
1381 return BP_RESULT_BADBIOSTABLE;
1383 info->gpu_cap_info =
1384 le32_to_cpu(info_v11->gpucapinfo);
1386 * system_config: Bit[0] = 0 : PCIE power gating disabled
1387 * = 1 : PCIE power gating enabled
1388 * Bit[1] = 0 : DDR-PLL shut down disabled
1389 * = 1 : DDR-PLL shut down enabled
1390 * Bit[2] = 0 : DDR-PLL power down disabled
1391 * = 1 : DDR-PLL power down enabled
1393 info->system_config = le32_to_cpu(info_v11->system_config);
1394 info->cpu_cap_info = le32_to_cpu(info_v11->cpucapinfo);
1395 info->memory_type = info_v11->memorytype;
1396 info->ma_channel_number = info_v11->umachannelnumber;
1397 info->lvds_ss_percentage =
1398 le16_to_cpu(info_v11->lvds_ss_percentage);
1399 info->lvds_sspread_rate_in_10hz =
1400 le16_to_cpu(info_v11->lvds_ss_rate_10hz);
1401 info->hdmi_ss_percentage =
1402 le16_to_cpu(info_v11->hdmi_ss_percentage);
1403 info->hdmi_sspread_rate_in_10hz =
1404 le16_to_cpu(info_v11->hdmi_ss_rate_10hz);
1405 info->dvi_ss_percentage =
1406 le16_to_cpu(info_v11->dvi_ss_percentage);
1407 info->dvi_sspread_rate_in_10_hz =
1408 le16_to_cpu(info_v11->dvi_ss_rate_10hz);
1409 info->lvds_misc = info_v11->lvds_misc;
1410 for (i = 0; i < NUMBER_OF_UCHAR_FOR_GUID; ++i) {
1411 info->ext_disp_conn_info.gu_id[i] =
1412 info_v11->extdispconninfo.guid[i];
1415 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; ++i) {
1416 info->ext_disp_conn_info.path[i].device_connector_id =
1417 object_id_from_bios_object_id(
1418 le16_to_cpu(info_v11->extdispconninfo.path[i].connectorobjid));
1420 info->ext_disp_conn_info.path[i].ext_encoder_obj_id =
1421 object_id_from_bios_object_id(
1423 info_v11->extdispconninfo.path[i].ext_encoder_objid));
1425 info->ext_disp_conn_info.path[i].device_tag =
1427 info_v11->extdispconninfo.path[i].device_tag);
1428 info->ext_disp_conn_info.path[i].device_acpi_enum =
1430 info_v11->extdispconninfo.path[i].device_acpi_enum);
1431 info->ext_disp_conn_info.path[i].ext_aux_ddc_lut_index =
1432 info_v11->extdispconninfo.path[i].auxddclut_index;
1433 info->ext_disp_conn_info.path[i].ext_hpd_pin_lut_index =
1434 info_v11->extdispconninfo.path[i].hpdlut_index;
1435 info->ext_disp_conn_info.path[i].channel_mapping.raw =
1436 info_v11->extdispconninfo.path[i].channelmapping;
1437 info->ext_disp_conn_info.path[i].caps =
1438 le16_to_cpu(info_v11->extdispconninfo.path[i].caps);
1440 info->ext_disp_conn_info.checksum =
1441 info_v11->extdispconninfo.checksum;
1443 info->dp0_ext_hdmi_slv_addr = info_v11->dp0_retimer_set.HdmiSlvAddr;
1444 info->dp0_ext_hdmi_reg_num = info_v11->dp0_retimer_set.HdmiRegNum;
1445 for (i = 0; i < info->dp0_ext_hdmi_reg_num; i++) {
1446 info->dp0_ext_hdmi_reg_settings[i].i2c_reg_index =
1447 info_v11->dp0_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
1448 info->dp0_ext_hdmi_reg_settings[i].i2c_reg_val =
1449 info_v11->dp0_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
1451 info->dp0_ext_hdmi_6g_reg_num = info_v11->dp0_retimer_set.Hdmi6GRegNum;
1452 for (i = 0; i < info->dp0_ext_hdmi_6g_reg_num; i++) {
1453 info->dp0_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
1454 info_v11->dp0_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
1455 info->dp0_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
1456 info_v11->dp0_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
1459 info->dp1_ext_hdmi_slv_addr = info_v11->dp1_retimer_set.HdmiSlvAddr;
1460 info->dp1_ext_hdmi_reg_num = info_v11->dp1_retimer_set.HdmiRegNum;
1461 for (i = 0; i < info->dp1_ext_hdmi_reg_num; i++) {
1462 info->dp1_ext_hdmi_reg_settings[i].i2c_reg_index =
1463 info_v11->dp1_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
1464 info->dp1_ext_hdmi_reg_settings[i].i2c_reg_val =
1465 info_v11->dp1_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
1467 info->dp1_ext_hdmi_6g_reg_num = info_v11->dp1_retimer_set.Hdmi6GRegNum;
1468 for (i = 0; i < info->dp1_ext_hdmi_6g_reg_num; i++) {
1469 info->dp1_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
1470 info_v11->dp1_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
1471 info->dp1_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
1472 info_v11->dp1_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
1475 info->dp2_ext_hdmi_slv_addr = info_v11->dp2_retimer_set.HdmiSlvAddr;
1476 info->dp2_ext_hdmi_reg_num = info_v11->dp2_retimer_set.HdmiRegNum;
1477 for (i = 0; i < info->dp2_ext_hdmi_reg_num; i++) {
1478 info->dp2_ext_hdmi_reg_settings[i].i2c_reg_index =
1479 info_v11->dp2_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
1480 info->dp2_ext_hdmi_reg_settings[i].i2c_reg_val =
1481 info_v11->dp2_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
1483 info->dp2_ext_hdmi_6g_reg_num = info_v11->dp2_retimer_set.Hdmi6GRegNum;
1484 for (i = 0; i < info->dp2_ext_hdmi_6g_reg_num; i++) {
1485 info->dp2_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
1486 info_v11->dp2_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
1487 info->dp2_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
1488 info_v11->dp2_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
1491 info->dp3_ext_hdmi_slv_addr = info_v11->dp3_retimer_set.HdmiSlvAddr;
1492 info->dp3_ext_hdmi_reg_num = info_v11->dp3_retimer_set.HdmiRegNum;
1493 for (i = 0; i < info->dp3_ext_hdmi_reg_num; i++) {
1494 info->dp3_ext_hdmi_reg_settings[i].i2c_reg_index =
1495 info_v11->dp3_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
1496 info->dp3_ext_hdmi_reg_settings[i].i2c_reg_val =
1497 info_v11->dp3_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
1499 info->dp3_ext_hdmi_6g_reg_num = info_v11->dp3_retimer_set.Hdmi6GRegNum;
1500 for (i = 0; i < info->dp3_ext_hdmi_6g_reg_num; i++) {
1501 info->dp3_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
1502 info_v11->dp3_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
1503 info->dp3_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
1504 info_v11->dp3_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
1508 /** TODO - review **/
1510 info->boot_up_engine_clock = le32_to_cpu(info_v11->ulBootUpEngineClock)
1512 info->dentist_vco_freq = le32_to_cpu(info_v11->ulDentistVCOFreq) * 10;
1513 info->boot_up_uma_clock = le32_to_cpu(info_v8->ulBootUpUMAClock) * 10;
1515 for (i = 0; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
1516 /* Convert [10KHz] into [KHz] */
1517 info->disp_clk_voltage[i].max_supported_clk =
1518 le32_to_cpu(info_v11->sDISPCLK_Voltage[i].
1519 ulMaximumSupportedCLK) * 10;
1520 info->disp_clk_voltage[i].voltage_index =
1521 le32_to_cpu(info_v11->sDISPCLK_Voltage[i].ulVoltageIndex);
1524 info->boot_up_req_display_vector =
1525 le32_to_cpu(info_v11->ulBootUpReqDisplayVector);
1526 info->boot_up_nb_voltage =
1527 le16_to_cpu(info_v11->usBootUpNBVoltage);
1528 info->ext_disp_conn_info_offset =
1529 le16_to_cpu(info_v11->usExtDispConnInfoOffset);
1530 info->gmc_restore_reset_time =
1531 le32_to_cpu(info_v11->ulGMCRestoreResetTime);
1532 info->minimum_n_clk =
1533 le32_to_cpu(info_v11->ulNbpStateNClkFreq[0]);
1534 for (i = 1; i < 4; ++i)
1535 info->minimum_n_clk =
1536 info->minimum_n_clk <
1537 le32_to_cpu(info_v11->ulNbpStateNClkFreq[i]) ?
1538 info->minimum_n_clk : le32_to_cpu(
1539 info_v11->ulNbpStateNClkFreq[i]);
1541 info->idle_n_clk = le32_to_cpu(info_v11->ulIdleNClk);
1542 info->ddr_dll_power_up_time =
1543 le32_to_cpu(info_v11->ulDDR_DLL_PowerUpTime);
1544 info->ddr_pll_power_up_time =
1545 le32_to_cpu(info_v11->ulDDR_PLL_PowerUpTime);
1546 info->pcie_clk_ss_type = le16_to_cpu(info_v11->usPCIEClkSSType);
1547 info->max_lvds_pclk_freq_in_single_link =
1548 le16_to_cpu(info_v11->usMaxLVDSPclkFreqInSingleLink);
1549 info->max_lvds_pclk_freq_in_single_link =
1550 le16_to_cpu(info_v11->usMaxLVDSPclkFreqInSingleLink);
1551 info->lvds_pwr_on_seq_dig_on_to_de_in_4ms =
1552 info_v11->ucLVDSPwrOnSeqDIGONtoDE_in4Ms;
1553 info->lvds_pwr_on_seq_de_to_vary_bl_in_4ms =
1554 info_v11->ucLVDSPwrOnSeqDEtoVARY_BL_in4Ms;
1555 info->lvds_pwr_on_seq_vary_bl_to_blon_in_4ms =
1556 info_v11->ucLVDSPwrOnSeqVARY_BLtoBLON_in4Ms;
1557 info->lvds_pwr_off_seq_vary_bl_to_de_in4ms =
1558 info_v11->ucLVDSPwrOffSeqVARY_BLtoDE_in4Ms;
1559 info->lvds_pwr_off_seq_de_to_dig_on_in4ms =
1560 info_v11->ucLVDSPwrOffSeqDEtoDIGON_in4Ms;
1561 info->lvds_pwr_off_seq_blon_to_vary_bl_in_4ms =
1562 info_v11->ucLVDSPwrOffSeqBLONtoVARY_BL_in4Ms;
1563 info->lvds_off_to_on_delay_in_4ms =
1564 info_v11->ucLVDSOffToOnDelay_in4Ms;
1565 info->lvds_bit_depth_control_val =
1566 le32_to_cpu(info_v11->ulLCDBitDepthControlVal);
1568 for (i = 0; i < NUMBER_OF_AVAILABLE_SCLK; ++i) {
1569 /* Convert [10KHz] into [KHz] */
1570 info->avail_s_clk[i].supported_s_clk =
1571 le32_to_cpu(info_v11->sAvail_SCLK[i].ulSupportedSCLK)
1573 info->avail_s_clk[i].voltage_index =
1574 le16_to_cpu(info_v11->sAvail_SCLK[i].usVoltageIndex);
1575 info->avail_s_clk[i].voltage_id =
1576 le16_to_cpu(info_v11->sAvail_SCLK[i].usVoltageID);
1580 return BP_RESULT_OK;
1585 * construct_integrated_info
1588 * Get integrated BIOS information based on table revision
1591 * bios_parser *bp - [in]BIOS parser handler to get master data table
1592 * integrated_info *info - [out] store and output integrated info
1595 * enum bp_result - BP_RESULT_OK if information is available,
1596 * BP_RESULT_BADBIOSTABLE otherwise.
1598 static enum bp_result construct_integrated_info(
1599 struct bios_parser *bp,
1600 struct integrated_info *info)
1602 enum bp_result result = BP_RESULT_BADBIOSTABLE;
1604 struct atom_common_table_header *header;
1605 struct atom_data_revision revision;
1607 struct clock_voltage_caps temp = {0, 0};
1611 if (info && DATA_TABLES(integratedsysteminfo)) {
1612 header = GET_IMAGE(struct atom_common_table_header,
1613 DATA_TABLES(integratedsysteminfo));
1615 get_atom_data_table_revision(header, &revision);
1617 /* Don't need to check major revision as they are all 1 */
1618 switch (revision.minor) {
1620 result = get_integrated_info_v11(bp, info);
1627 if (result != BP_RESULT_OK)
1630 /* Sort voltage table from low to high*/
1631 for (i = 1; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
1632 for (j = i; j > 0; --j) {
1633 if (info->disp_clk_voltage[j].max_supported_clk <
1634 info->disp_clk_voltage[j-1].max_supported_clk
1636 /* swap j and j - 1*/
1637 temp = info->disp_clk_voltage[j-1];
1638 info->disp_clk_voltage[j-1] =
1639 info->disp_clk_voltage[j];
1640 info->disp_clk_voltage[j] = temp;
1648 static struct integrated_info *bios_parser_create_integrated_info(
1649 struct dc_bios *dcb)
1651 struct bios_parser *bp = BP_FROM_DCB(dcb);
1652 struct integrated_info *info = NULL;
1654 info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);
1661 if (construct_integrated_info(bp, info) == BP_RESULT_OK)
1669 static enum bp_result update_slot_layout_info(
1670 struct dc_bios *dcb,
1672 struct slot_layout_info *slot_layout_info)
1674 unsigned int record_offset;
1676 struct atom_display_object_path_v2 *object;
1677 struct atom_bracket_layout_record *record;
1678 struct atom_common_record_header *record_header;
1679 enum bp_result result;
1680 struct bios_parser *bp;
1681 struct object_info_table *tbl;
1682 struct display_object_info_table_v1_4 *v1_4;
1685 record_header = NULL;
1686 result = BP_RESULT_NORECORD;
1688 bp = BP_FROM_DCB(dcb);
1689 tbl = &bp->object_info_tbl;
1692 object = &v1_4->display_path[i];
1693 record_offset = (unsigned int)
1694 (object->disp_recordoffset) +
1695 (unsigned int)(bp->object_info_tbl_offset);
1699 record_header = (struct atom_common_record_header *)
1700 GET_IMAGE(struct atom_common_record_header,
1702 if (record_header == NULL) {
1703 result = BP_RESULT_BADBIOSTABLE;
1707 /* the end of the list */
1708 if (record_header->record_type == 0xff ||
1709 record_header->record_size == 0) {
1713 if (record_header->record_type ==
1714 ATOM_BRACKET_LAYOUT_RECORD_TYPE &&
1715 sizeof(struct atom_bracket_layout_record)
1716 <= record_header->record_size) {
1717 record = (struct atom_bracket_layout_record *)
1719 result = BP_RESULT_OK;
1723 record_offset += record_header->record_size;
1726 /* return if the record not found */
1727 if (result != BP_RESULT_OK)
1730 /* get slot sizes */
1731 slot_layout_info->length = record->bracketlen;
1732 slot_layout_info->width = record->bracketwidth;
1734 /* get info for each connector in the slot */
1735 slot_layout_info->num_of_connectors = record->conn_num;
1736 for (j = 0; j < slot_layout_info->num_of_connectors; ++j) {
1737 slot_layout_info->connectors[j].connector_type =
1738 (enum connector_layout_type)
1739 (record->conn_info[j].connector_type);
1740 switch (record->conn_info[j].connector_type) {
1741 case CONNECTOR_TYPE_DVI_D:
1742 slot_layout_info->connectors[j].connector_type =
1743 CONNECTOR_LAYOUT_TYPE_DVI_D;
1744 slot_layout_info->connectors[j].length =
1748 case CONNECTOR_TYPE_HDMI:
1749 slot_layout_info->connectors[j].connector_type =
1750 CONNECTOR_LAYOUT_TYPE_HDMI;
1751 slot_layout_info->connectors[j].length =
1752 CONNECTOR_SIZE_HDMI;
1755 case CONNECTOR_TYPE_DISPLAY_PORT:
1756 slot_layout_info->connectors[j].connector_type =
1757 CONNECTOR_LAYOUT_TYPE_DP;
1758 slot_layout_info->connectors[j].length =
1762 case CONNECTOR_TYPE_MINI_DISPLAY_PORT:
1763 slot_layout_info->connectors[j].connector_type =
1764 CONNECTOR_LAYOUT_TYPE_MINI_DP;
1765 slot_layout_info->connectors[j].length =
1766 CONNECTOR_SIZE_MINI_DP;
1770 slot_layout_info->connectors[j].connector_type =
1771 CONNECTOR_LAYOUT_TYPE_UNKNOWN;
1772 slot_layout_info->connectors[j].length =
1773 CONNECTOR_SIZE_UNKNOWN;
1776 slot_layout_info->connectors[j].position =
1777 record->conn_info[j].position;
1778 slot_layout_info->connectors[j].connector_id =
1779 object_id_from_bios_object_id(
1780 record->conn_info[j].connectorobjid);
1786 static enum bp_result get_bracket_layout_record(
1787 struct dc_bios *dcb,
1788 unsigned int bracket_layout_id,
1789 struct slot_layout_info *slot_layout_info)
1792 struct bios_parser *bp = BP_FROM_DCB(dcb);
1793 enum bp_result result;
1794 struct object_info_table *tbl;
1795 struct display_object_info_table_v1_4 *v1_4;
1797 if (slot_layout_info == NULL) {
1798 DC_LOG_DETECTION_EDID_PARSER("Invalid slot_layout_info\n");
1799 return BP_RESULT_BADINPUT;
1801 tbl = &bp->object_info_tbl;
1804 result = BP_RESULT_NORECORD;
1805 for (i = 0; i < v1_4->number_of_path; ++i) {
1807 if (bracket_layout_id ==
1808 v1_4->display_path[i].display_objid) {
1809 result = update_slot_layout_info(dcb, i,
1817 static enum bp_result bios_get_board_layout_info(
1818 struct dc_bios *dcb,
1819 struct board_layout_info *board_layout_info)
1822 struct bios_parser *bp;
1823 enum bp_result record_result;
1825 const unsigned int slot_index_to_vbios_id[MAX_BOARD_SLOTS] = {
1826 GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID1,
1827 GENERICOBJECT_BRACKET_LAYOUT_ENUM_ID2,
1831 bp = BP_FROM_DCB(dcb);
1832 if (board_layout_info == NULL) {
1833 DC_LOG_DETECTION_EDID_PARSER("Invalid board_layout_info\n");
1834 return BP_RESULT_BADINPUT;
1837 board_layout_info->num_of_slots = 0;
1839 for (i = 0; i < MAX_BOARD_SLOTS; ++i) {
1840 record_result = get_bracket_layout_record(dcb,
1841 slot_index_to_vbios_id[i],
1842 &board_layout_info->slots[i]);
1844 if (record_result == BP_RESULT_NORECORD && i > 0)
1845 break; /* no more slots present in bios */
1846 else if (record_result != BP_RESULT_OK)
1847 return record_result; /* fail */
1849 ++board_layout_info->num_of_slots;
1852 /* all data is valid */
1853 board_layout_info->is_number_of_slots_valid = 1;
1854 board_layout_info->is_slots_size_valid = 1;
1855 board_layout_info->is_connector_offsets_valid = 1;
1856 board_layout_info->is_connector_lengths_valid = 1;
1858 return BP_RESULT_OK;
1861 static const struct dc_vbios_funcs vbios_funcs = {
1862 .get_connectors_number = bios_parser_get_connectors_number,
1864 .get_connector_id = bios_parser_get_connector_id,
1866 .get_src_obj = bios_parser_get_src_obj,
1868 .get_i2c_info = bios_parser_get_i2c_info,
1870 .get_hpd_info = bios_parser_get_hpd_info,
1872 .get_device_tag = bios_parser_get_device_tag,
1874 .get_firmware_info = bios_parser_get_firmware_info,
1876 .get_spread_spectrum_info = bios_parser_get_spread_spectrum_info,
1878 .get_ss_entry_number = bios_parser_get_ss_entry_number,
1880 .get_embedded_panel_info = bios_parser_get_embedded_panel_info,
1882 .get_gpio_pin_info = bios_parser_get_gpio_pin_info,
1884 .get_encoder_cap_info = bios_parser_get_encoder_cap_info,
1886 .is_device_id_supported = bios_parser_is_device_id_supported,
1888 .is_accelerated_mode = bios_parser_is_accelerated_mode,
1890 .set_scratch_critical_state = bios_parser_set_scratch_critical_state,
1894 .encoder_control = bios_parser_encoder_control,
1896 .transmitter_control = bios_parser_transmitter_control,
1898 .enable_crtc = bios_parser_enable_crtc,
1900 .set_pixel_clock = bios_parser_set_pixel_clock,
1902 .set_dce_clock = bios_parser_set_dce_clock,
1904 .program_crtc_timing = bios_parser_program_crtc_timing,
1906 .enable_disp_power_gating = bios_parser_enable_disp_power_gating,
1908 .bios_parser_destroy = firmware_parser_destroy,
1910 .get_board_layout_info = bios_get_board_layout_info,
1913 static bool bios_parser_construct(
1914 struct bios_parser *bp,
1915 struct bp_init_data *init,
1916 enum dce_version dce_version)
1918 uint16_t *rom_header_offset = NULL;
1919 struct atom_rom_header_v2_2 *rom_header = NULL;
1920 struct display_object_info_table_v1_4 *object_info_tbl;
1921 struct atom_data_revision tbl_rev = {0};
1929 bp->base.funcs = &vbios_funcs;
1930 bp->base.bios = init->bios;
1931 bp->base.bios_size = bp->base.bios[OFFSET_TO_ATOM_ROM_IMAGE_SIZE] * BIOS_IMAGE_SIZE_UNIT;
1933 bp->base.ctx = init->ctx;
1935 bp->base.bios_local_image = NULL;
1938 GET_IMAGE(uint16_t, OFFSET_TO_ATOM_ROM_HEADER_POINTER);
1940 if (!rom_header_offset)
1943 rom_header = GET_IMAGE(struct atom_rom_header_v2_2, *rom_header_offset);
1948 get_atom_data_table_revision(&rom_header->table_header, &tbl_rev);
1949 if (!(tbl_rev.major >= 2 && tbl_rev.minor >= 2))
1952 bp->master_data_tbl =
1953 GET_IMAGE(struct atom_master_data_table_v2_1,
1954 rom_header->masterdatatable_offset);
1956 if (!bp->master_data_tbl)
1959 bp->object_info_tbl_offset = DATA_TABLES(displayobjectinfo);
1961 if (!bp->object_info_tbl_offset)
1965 GET_IMAGE(struct display_object_info_table_v1_4,
1966 bp->object_info_tbl_offset);
1968 if (!object_info_tbl)
1971 get_atom_data_table_revision(&object_info_tbl->table_header,
1972 &bp->object_info_tbl.revision);
1974 if (bp->object_info_tbl.revision.major == 1
1975 && bp->object_info_tbl.revision.minor >= 4) {
1976 struct display_object_info_table_v1_4 *tbl_v1_4;
1978 tbl_v1_4 = GET_IMAGE(struct display_object_info_table_v1_4,
1979 bp->object_info_tbl_offset);
1983 bp->object_info_tbl.v1_4 = tbl_v1_4;
1987 dal_firmware_parser_init_cmd_tbl(bp);
1988 dal_bios_parser_init_cmd_tbl_helper2(&bp->cmd_helper, dce_version);
1990 bp->base.integrated_info = bios_parser_create_integrated_info(&bp->base);
1995 struct dc_bios *firmware_parser_create(
1996 struct bp_init_data *init,
1997 enum dce_version dce_version)
1999 struct bios_parser *bp = NULL;
2001 bp = kzalloc(sizeof(struct bios_parser), GFP_KERNEL);
2005 if (bios_parser_construct(bp, init, dce_version))