bios_parser2.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  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. #include "dm_services.h"
  26. #include "ObjectID.h"
  27. #include "atomfirmware.h"
  28. #include "dc_bios_types.h"
  29. #include "include/grph_object_ctrl_defs.h"
  30. #include "include/bios_parser_interface.h"
  31. #include "include/i2caux_interface.h"
  32. #include "include/logger_interface.h"
  33. #include "command_table2.h"
  34. #include "bios_parser_helper.h"
  35. #include "command_table_helper2.h"
  36. #include "bios_parser2.h"
  37. #include "bios_parser_types_internal2.h"
  38. #include "bios_parser_interface.h"
  39. #include "bios_parser_common.h"
  40. #define LAST_RECORD_TYPE 0xff
  41. #define SMU9_SYSPLL0_ID 0
  42. struct i2c_id_config_access {
  43. uint8_t bfI2C_LineMux:4;
  44. uint8_t bfHW_EngineID:3;
  45. uint8_t bfHW_Capable:1;
  46. uint8_t ucAccess;
  47. };
  48. static enum bp_result get_gpio_i2c_info(struct bios_parser *bp,
  49. struct atom_i2c_record *record,
  50. struct graphics_object_i2c_info *info);
  51. static enum bp_result bios_parser_get_firmware_info(
  52. struct dc_bios *dcb,
  53. struct dc_firmware_info *info);
  54. static enum bp_result bios_parser_get_encoder_cap_info(
  55. struct dc_bios *dcb,
  56. struct graphics_object_id object_id,
  57. struct bp_encoder_cap_info *info);
  58. static enum bp_result get_firmware_info_v3_1(
  59. struct bios_parser *bp,
  60. struct dc_firmware_info *info);
  61. static struct atom_hpd_int_record *get_hpd_record(struct bios_parser *bp,
  62. struct atom_display_object_path_v2 *object);
  63. static struct atom_encoder_caps_record *get_encoder_cap_record(
  64. struct bios_parser *bp,
  65. struct atom_display_object_path_v2 *object);
  66. #define BIOS_IMAGE_SIZE_OFFSET 2
  67. #define BIOS_IMAGE_SIZE_UNIT 512
  68. #define DATA_TABLES(table) (bp->master_data_tbl->listOfdatatables.table)
  69. static void destruct(struct bios_parser *bp)
  70. {
  71. kfree(bp->base.bios_local_image);
  72. kfree(bp->base.integrated_info);
  73. }
  74. static void firmware_parser_destroy(struct dc_bios **dcb)
  75. {
  76. struct bios_parser *bp = BP_FROM_DCB(*dcb);
  77. if (!bp) {
  78. BREAK_TO_DEBUGGER();
  79. return;
  80. }
  81. destruct(bp);
  82. kfree(bp);
  83. *dcb = NULL;
  84. }
  85. static void get_atom_data_table_revision(
  86. struct atom_common_table_header *atom_data_tbl,
  87. struct atom_data_revision *tbl_revision)
  88. {
  89. if (!tbl_revision)
  90. return;
  91. /* initialize the revision to 0 which is invalid revision */
  92. tbl_revision->major = 0;
  93. tbl_revision->minor = 0;
  94. if (!atom_data_tbl)
  95. return;
  96. tbl_revision->major =
  97. (uint32_t) atom_data_tbl->format_revision & 0x3f;
  98. tbl_revision->minor =
  99. (uint32_t) atom_data_tbl->content_revision & 0x3f;
  100. }
  101. /* BIOS oject table displaypath is per connector.
  102. * There is extra path not for connector. BIOS fill its encoderid as 0
  103. */
  104. static uint8_t bios_parser_get_connectors_number(struct dc_bios *dcb)
  105. {
  106. struct bios_parser *bp = BP_FROM_DCB(dcb);
  107. unsigned int count = 0;
  108. unsigned int i;
  109. for (i = 0; i < bp->object_info_tbl.v1_4->number_of_path; i++) {
  110. if (bp->object_info_tbl.v1_4->display_path[i].encoderobjid != 0)
  111. count++;
  112. }
  113. return count;
  114. }
  115. static struct graphics_object_id bios_parser_get_encoder_id(
  116. struct dc_bios *dcb,
  117. uint32_t i)
  118. {
  119. struct bios_parser *bp = BP_FROM_DCB(dcb);
  120. struct graphics_object_id object_id = dal_graphics_object_id_init(
  121. 0, ENUM_ID_UNKNOWN, OBJECT_TYPE_UNKNOWN);
  122. if (bp->object_info_tbl.v1_4->number_of_path > i)
  123. object_id = object_id_from_bios_object_id(
  124. bp->object_info_tbl.v1_4->display_path[i].encoderobjid);
  125. return object_id;
  126. }
  127. static struct graphics_object_id bios_parser_get_connector_id(
  128. struct dc_bios *dcb,
  129. uint8_t i)
  130. {
  131. struct bios_parser *bp = BP_FROM_DCB(dcb);
  132. struct graphics_object_id object_id = dal_graphics_object_id_init(
  133. 0, ENUM_ID_UNKNOWN, OBJECT_TYPE_UNKNOWN);
  134. struct object_info_table *tbl = &bp->object_info_tbl;
  135. struct display_object_info_table_v1_4 *v1_4 = tbl->v1_4;
  136. if (v1_4->number_of_path > i) {
  137. /* If display_objid is generic object id, the encoderObj
  138. * /extencoderobjId should be 0
  139. */
  140. if (v1_4->display_path[i].encoderobjid != 0 &&
  141. v1_4->display_path[i].display_objid != 0)
  142. object_id = object_id_from_bios_object_id(
  143. v1_4->display_path[i].display_objid);
  144. }
  145. return object_id;
  146. }
  147. /* TODO: GetNumberOfSrc*/
  148. static uint32_t bios_parser_get_dst_number(struct dc_bios *dcb,
  149. struct graphics_object_id id)
  150. {
  151. /* connector has 1 Dest, encoder has 0 Dest */
  152. switch (id.type) {
  153. case OBJECT_TYPE_ENCODER:
  154. return 0;
  155. case OBJECT_TYPE_CONNECTOR:
  156. return 1;
  157. default:
  158. return 0;
  159. }
  160. }
  161. /* removed getSrcObjList, getDestObjList*/
  162. static enum bp_result bios_parser_get_src_obj(struct dc_bios *dcb,
  163. struct graphics_object_id object_id, uint32_t index,
  164. struct graphics_object_id *src_object_id)
  165. {
  166. struct bios_parser *bp = BP_FROM_DCB(dcb);
  167. unsigned int i;
  168. enum bp_result bp_result = BP_RESULT_BADINPUT;
  169. struct graphics_object_id obj_id = {0};
  170. struct object_info_table *tbl = &bp->object_info_tbl;
  171. if (!src_object_id)
  172. return bp_result;
  173. switch (object_id.type) {
  174. /* Encoder's Source is GPU. BIOS does not provide GPU, since all
  175. * displaypaths point to same GPU (0x1100). Hardcode GPU object type
  176. */
  177. case OBJECT_TYPE_ENCODER:
  178. /* TODO: since num of src must be less than 2.
  179. * If found in for loop, should break.
  180. * DAL2 implementation may be changed too
  181. */
  182. for (i = 0; i < tbl->v1_4->number_of_path; i++) {
  183. obj_id = object_id_from_bios_object_id(
  184. tbl->v1_4->display_path[i].encoderobjid);
  185. if (object_id.type == obj_id.type &&
  186. object_id.id == obj_id.id &&
  187. object_id.enum_id ==
  188. obj_id.enum_id) {
  189. *src_object_id =
  190. object_id_from_bios_object_id(0x1100);
  191. /* break; */
  192. }
  193. }
  194. bp_result = BP_RESULT_OK;
  195. break;
  196. case OBJECT_TYPE_CONNECTOR:
  197. for (i = 0; i < tbl->v1_4->number_of_path; i++) {
  198. obj_id = object_id_from_bios_object_id(
  199. tbl->v1_4->display_path[i].display_objid);
  200. if (object_id.type == obj_id.type &&
  201. object_id.id == obj_id.id &&
  202. object_id.enum_id == obj_id.enum_id) {
  203. *src_object_id =
  204. object_id_from_bios_object_id(
  205. tbl->v1_4->display_path[i].encoderobjid);
  206. /* break; */
  207. }
  208. }
  209. bp_result = BP_RESULT_OK;
  210. break;
  211. default:
  212. break;
  213. }
  214. return bp_result;
  215. }
  216. static enum bp_result bios_parser_get_dst_obj(struct dc_bios *dcb,
  217. struct graphics_object_id object_id, uint32_t index,
  218. struct graphics_object_id *dest_object_id)
  219. {
  220. struct bios_parser *bp = BP_FROM_DCB(dcb);
  221. unsigned int i;
  222. enum bp_result bp_result = BP_RESULT_BADINPUT;
  223. struct graphics_object_id obj_id = {0};
  224. struct object_info_table *tbl = &bp->object_info_tbl;
  225. if (!dest_object_id)
  226. return BP_RESULT_BADINPUT;
  227. switch (object_id.type) {
  228. case OBJECT_TYPE_ENCODER:
  229. /* TODO: since num of src must be less than 2.
  230. * If found in for loop, should break.
  231. * DAL2 implementation may be changed too
  232. */
  233. for (i = 0; i < tbl->v1_4->number_of_path; i++) {
  234. obj_id = object_id_from_bios_object_id(
  235. tbl->v1_4->display_path[i].encoderobjid);
  236. if (object_id.type == obj_id.type &&
  237. object_id.id == obj_id.id &&
  238. object_id.enum_id ==
  239. obj_id.enum_id) {
  240. *dest_object_id =
  241. object_id_from_bios_object_id(
  242. tbl->v1_4->display_path[i].display_objid);
  243. /* break; */
  244. }
  245. }
  246. bp_result = BP_RESULT_OK;
  247. break;
  248. default:
  249. break;
  250. }
  251. return bp_result;
  252. }
  253. /* from graphics_object_id, find display path which includes the object_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. switch (id.type) {
  261. case OBJECT_TYPE_ENCODER:
  262. for (i = 0; i < bp->object_info_tbl.v1_4->number_of_path; i++) {
  263. obj_id = object_id_from_bios_object_id(
  264. bp->object_info_tbl.v1_4->display_path[i].encoderobjid);
  265. if (id.type == obj_id.type &&
  266. id.id == obj_id.id &&
  267. id.enum_id == obj_id.enum_id)
  268. return
  269. &bp->object_info_tbl.v1_4->display_path[i];
  270. }
  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. );
  280. if (id.type == obj_id.type &&
  281. id.id == obj_id.id &&
  282. id.enum_id == obj_id.enum_id)
  283. return
  284. &bp->object_info_tbl.v1_4->display_path[i];
  285. }
  286. default:
  287. return NULL;
  288. }
  289. }
  290. static enum bp_result bios_parser_get_i2c_info(struct dc_bios *dcb,
  291. struct graphics_object_id id,
  292. struct graphics_object_i2c_info *info)
  293. {
  294. uint32_t offset;
  295. struct atom_display_object_path_v2 *object;
  296. struct atom_common_record_header *header;
  297. struct atom_i2c_record *record;
  298. struct bios_parser *bp = BP_FROM_DCB(dcb);
  299. if (!info)
  300. return BP_RESULT_BADINPUT;
  301. object = get_bios_object(bp, id);
  302. if (!object)
  303. return BP_RESULT_BADINPUT;
  304. offset = object->disp_recordoffset + bp->object_info_tbl_offset;
  305. for (;;) {
  306. header = GET_IMAGE(struct atom_common_record_header, offset);
  307. if (!header)
  308. return BP_RESULT_BADBIOSTABLE;
  309. if (header->record_type == LAST_RECORD_TYPE ||
  310. !header->record_size)
  311. break;
  312. if (header->record_type == ATOM_I2C_RECORD_TYPE
  313. && sizeof(struct atom_i2c_record) <=
  314. header->record_size) {
  315. /* get the I2C info */
  316. record = (struct atom_i2c_record *) header;
  317. if (get_gpio_i2c_info(bp, record, info) ==
  318. BP_RESULT_OK)
  319. return BP_RESULT_OK;
  320. }
  321. offset += header->record_size;
  322. }
  323. return BP_RESULT_NORECORD;
  324. }
  325. static enum bp_result get_gpio_i2c_info(
  326. struct bios_parser *bp,
  327. struct atom_i2c_record *record,
  328. struct graphics_object_i2c_info *info)
  329. {
  330. struct atom_gpio_pin_lut_v2_1 *header;
  331. uint32_t count = 0;
  332. unsigned int table_index = 0;
  333. if (!info)
  334. return BP_RESULT_BADINPUT;
  335. /* get the GPIO_I2C info */
  336. if (!DATA_TABLES(gpio_pin_lut))
  337. return BP_RESULT_BADBIOSTABLE;
  338. header = GET_IMAGE(struct atom_gpio_pin_lut_v2_1,
  339. DATA_TABLES(gpio_pin_lut));
  340. if (!header)
  341. return BP_RESULT_BADBIOSTABLE;
  342. if (sizeof(struct atom_common_table_header) +
  343. sizeof(struct atom_gpio_pin_assignment) >
  344. le16_to_cpu(header->table_header.structuresize))
  345. return BP_RESULT_BADBIOSTABLE;
  346. /* TODO: is version change? */
  347. if (header->table_header.content_revision != 1)
  348. return BP_RESULT_UNSUPPORTED;
  349. /* get data count */
  350. count = (le16_to_cpu(header->table_header.structuresize)
  351. - sizeof(struct atom_common_table_header))
  352. / sizeof(struct atom_gpio_pin_assignment);
  353. table_index = record->i2c_id & I2C_HW_LANE_MUX;
  354. if (count < table_index) {
  355. bool find_valid = false;
  356. for (table_index = 0; table_index < count; table_index++) {
  357. if (((record->i2c_id & I2C_HW_CAP) == (
  358. header->gpio_pin[table_index].gpio_id &
  359. I2C_HW_CAP)) &&
  360. ((record->i2c_id & I2C_HW_ENGINE_ID_MASK) ==
  361. (header->gpio_pin[table_index].gpio_id &
  362. I2C_HW_ENGINE_ID_MASK)) &&
  363. ((record->i2c_id & I2C_HW_LANE_MUX) ==
  364. (header->gpio_pin[table_index].gpio_id &
  365. I2C_HW_LANE_MUX))) {
  366. /* still valid */
  367. find_valid = true;
  368. break;
  369. }
  370. }
  371. /* If we don't find the entry that we are looking for then
  372. * we will return BP_Result_BadBiosTable.
  373. */
  374. if (find_valid == false)
  375. return BP_RESULT_BADBIOSTABLE;
  376. }
  377. /* get the GPIO_I2C_INFO */
  378. info->i2c_hw_assist = (record->i2c_id & I2C_HW_CAP) ? true : false;
  379. info->i2c_line = record->i2c_id & I2C_HW_LANE_MUX;
  380. info->i2c_engine_id = (record->i2c_id & I2C_HW_ENGINE_ID_MASK) >> 4;
  381. info->i2c_slave_address = record->i2c_slave_addr;
  382. /* TODO: check how to get register offset for en, Y, etc. */
  383. info->gpio_info.clk_a_register_index =
  384. le16_to_cpu(
  385. header->gpio_pin[table_index].data_a_reg_index);
  386. info->gpio_info.clk_a_shift =
  387. header->gpio_pin[table_index].gpio_bitshift;
  388. return BP_RESULT_OK;
  389. }
  390. static enum bp_result get_voltage_ddc_info_v4(
  391. uint8_t *i2c_line,
  392. uint32_t index,
  393. struct atom_common_table_header *header,
  394. uint8_t *address)
  395. {
  396. enum bp_result result = BP_RESULT_NORECORD;
  397. struct atom_voltage_objects_info_v4_1 *info =
  398. (struct atom_voltage_objects_info_v4_1 *) address;
  399. uint8_t *voltage_current_object =
  400. (uint8_t *) (&(info->voltage_object[0]));
  401. while ((address + le16_to_cpu(header->structuresize)) >
  402. voltage_current_object) {
  403. struct atom_i2c_voltage_object_v4 *object =
  404. (struct atom_i2c_voltage_object_v4 *)
  405. voltage_current_object;
  406. if (object->header.voltage_mode ==
  407. ATOM_INIT_VOLTAGE_REGULATOR) {
  408. if (object->header.voltage_type == index) {
  409. *i2c_line = object->i2c_id ^ 0x90;
  410. result = BP_RESULT_OK;
  411. break;
  412. }
  413. }
  414. voltage_current_object +=
  415. le16_to_cpu(object->header.object_size);
  416. }
  417. return result;
  418. }
  419. static enum bp_result bios_parser_get_thermal_ddc_info(
  420. struct dc_bios *dcb,
  421. uint32_t i2c_channel_id,
  422. struct graphics_object_i2c_info *info)
  423. {
  424. struct bios_parser *bp = BP_FROM_DCB(dcb);
  425. struct i2c_id_config_access *config;
  426. struct atom_i2c_record record;
  427. if (!info)
  428. return BP_RESULT_BADINPUT;
  429. config = (struct i2c_id_config_access *) &i2c_channel_id;
  430. record.i2c_id = config->bfHW_Capable;
  431. record.i2c_id |= config->bfI2C_LineMux;
  432. record.i2c_id |= config->bfHW_EngineID;
  433. return get_gpio_i2c_info(bp, &record, info);
  434. }
  435. static enum bp_result bios_parser_get_voltage_ddc_info(struct dc_bios *dcb,
  436. uint32_t index,
  437. struct graphics_object_i2c_info *info)
  438. {
  439. uint8_t i2c_line = 0;
  440. enum bp_result result = BP_RESULT_NORECORD;
  441. uint8_t *voltage_info_address;
  442. struct atom_common_table_header *header;
  443. struct atom_data_revision revision = {0};
  444. struct bios_parser *bp = BP_FROM_DCB(dcb);
  445. if (!DATA_TABLES(voltageobject_info))
  446. return result;
  447. voltage_info_address = bios_get_image(&bp->base,
  448. DATA_TABLES(voltageobject_info),
  449. sizeof(struct atom_common_table_header));
  450. header = (struct atom_common_table_header *) voltage_info_address;
  451. get_atom_data_table_revision(header, &revision);
  452. switch (revision.major) {
  453. case 4:
  454. if (revision.minor != 1)
  455. break;
  456. result = get_voltage_ddc_info_v4(&i2c_line, index, header,
  457. voltage_info_address);
  458. break;
  459. }
  460. if (result == BP_RESULT_OK)
  461. result = bios_parser_get_thermal_ddc_info(dcb,
  462. i2c_line, info);
  463. return result;
  464. }
  465. static enum bp_result bios_parser_get_hpd_info(
  466. struct dc_bios *dcb,
  467. struct graphics_object_id id,
  468. struct graphics_object_hpd_info *info)
  469. {
  470. struct bios_parser *bp = BP_FROM_DCB(dcb);
  471. struct atom_display_object_path_v2 *object;
  472. struct atom_hpd_int_record *record = NULL;
  473. if (!info)
  474. return BP_RESULT_BADINPUT;
  475. object = get_bios_object(bp, id);
  476. if (!object)
  477. return BP_RESULT_BADINPUT;
  478. record = get_hpd_record(bp, object);
  479. if (record != NULL) {
  480. info->hpd_int_gpio_uid = record->pin_id;
  481. info->hpd_active = record->plugin_pin_state;
  482. return BP_RESULT_OK;
  483. }
  484. return BP_RESULT_NORECORD;
  485. }
  486. static struct atom_hpd_int_record *get_hpd_record(
  487. struct bios_parser *bp,
  488. struct atom_display_object_path_v2 *object)
  489. {
  490. struct atom_common_record_header *header;
  491. uint32_t offset;
  492. if (!object) {
  493. BREAK_TO_DEBUGGER(); /* Invalid object */
  494. return NULL;
  495. }
  496. offset = le16_to_cpu(object->disp_recordoffset)
  497. + bp->object_info_tbl_offset;
  498. for (;;) {
  499. header = GET_IMAGE(struct atom_common_record_header, offset);
  500. if (!header)
  501. return NULL;
  502. if (header->record_type == LAST_RECORD_TYPE ||
  503. !header->record_size)
  504. break;
  505. if (header->record_type == ATOM_HPD_INT_RECORD_TYPE
  506. && sizeof(struct atom_hpd_int_record) <=
  507. header->record_size)
  508. return (struct atom_hpd_int_record *) header;
  509. offset += header->record_size;
  510. }
  511. return NULL;
  512. }
  513. /**
  514. * bios_parser_get_gpio_pin_info
  515. * Get GpioPin information of input gpio id
  516. *
  517. * @param gpio_id, GPIO ID
  518. * @param info, GpioPin information structure
  519. * @return Bios parser result code
  520. * @note
  521. * to get the GPIO PIN INFO, we need:
  522. * 1. get the GPIO_ID from other object table, see GetHPDInfo()
  523. * 2. in DATA_TABLE.GPIO_Pin_LUT, search all records,
  524. * to get the registerA offset/mask
  525. */
  526. static enum bp_result bios_parser_get_gpio_pin_info(
  527. struct dc_bios *dcb,
  528. uint32_t gpio_id,
  529. struct gpio_pin_info *info)
  530. {
  531. struct bios_parser *bp = BP_FROM_DCB(dcb);
  532. struct atom_gpio_pin_lut_v2_1 *header;
  533. uint32_t count = 0;
  534. uint32_t i = 0;
  535. if (!DATA_TABLES(gpio_pin_lut))
  536. return BP_RESULT_BADBIOSTABLE;
  537. header = GET_IMAGE(struct atom_gpio_pin_lut_v2_1,
  538. DATA_TABLES(gpio_pin_lut));
  539. if (!header)
  540. return BP_RESULT_BADBIOSTABLE;
  541. if (sizeof(struct atom_common_table_header) +
  542. sizeof(struct atom_gpio_pin_lut_v2_1)
  543. > le16_to_cpu(header->table_header.structuresize))
  544. return BP_RESULT_BADBIOSTABLE;
  545. if (header->table_header.content_revision != 1)
  546. return BP_RESULT_UNSUPPORTED;
  547. /* Temporary hard code gpio pin info */
  548. #if defined(FOR_SIMNOW_BOOT)
  549. {
  550. struct atom_gpio_pin_assignment gpio_pin[8] = {
  551. {0x5db5, 0, 0, 1, 0},
  552. {0x5db5, 8, 8, 2, 0},
  553. {0x5db5, 0x10, 0x10, 3, 0},
  554. {0x5db5, 0x18, 0x14, 4, 0},
  555. {0x5db5, 0x1A, 0x18, 5, 0},
  556. {0x5db5, 0x1C, 0x1C, 6, 0},
  557. };
  558. count = 6;
  559. memmove(header->gpio_pin, gpio_pin, sizeof(gpio_pin));
  560. }
  561. #else
  562. count = (le16_to_cpu(header->table_header.structuresize)
  563. - sizeof(struct atom_common_table_header))
  564. / sizeof(struct atom_gpio_pin_assignment);
  565. #endif
  566. for (i = 0; i < count; ++i) {
  567. if (header->gpio_pin[i].gpio_id != gpio_id)
  568. continue;
  569. info->offset =
  570. (uint32_t) le16_to_cpu(
  571. header->gpio_pin[i].data_a_reg_index);
  572. info->offset_y = info->offset + 2;
  573. info->offset_en = info->offset + 1;
  574. info->offset_mask = info->offset - 1;
  575. info->mask = (uint32_t) (1 <<
  576. header->gpio_pin[i].gpio_bitshift);
  577. info->mask_y = info->mask + 2;
  578. info->mask_en = info->mask + 1;
  579. info->mask_mask = info->mask - 1;
  580. return BP_RESULT_OK;
  581. }
  582. return BP_RESULT_NORECORD;
  583. }
  584. static struct device_id device_type_from_device_id(uint16_t device_id)
  585. {
  586. struct device_id result_device_id;
  587. result_device_id.raw_device_tag = device_id;
  588. switch (device_id) {
  589. case ATOM_DISPLAY_LCD1_SUPPORT:
  590. result_device_id.device_type = DEVICE_TYPE_LCD;
  591. result_device_id.enum_id = 1;
  592. break;
  593. case ATOM_DISPLAY_DFP1_SUPPORT:
  594. result_device_id.device_type = DEVICE_TYPE_DFP;
  595. result_device_id.enum_id = 1;
  596. break;
  597. case ATOM_DISPLAY_DFP2_SUPPORT:
  598. result_device_id.device_type = DEVICE_TYPE_DFP;
  599. result_device_id.enum_id = 2;
  600. break;
  601. case ATOM_DISPLAY_DFP3_SUPPORT:
  602. result_device_id.device_type = DEVICE_TYPE_DFP;
  603. result_device_id.enum_id = 3;
  604. break;
  605. case ATOM_DISPLAY_DFP4_SUPPORT:
  606. result_device_id.device_type = DEVICE_TYPE_DFP;
  607. result_device_id.enum_id = 4;
  608. break;
  609. case ATOM_DISPLAY_DFP5_SUPPORT:
  610. result_device_id.device_type = DEVICE_TYPE_DFP;
  611. result_device_id.enum_id = 5;
  612. break;
  613. case ATOM_DISPLAY_DFP6_SUPPORT:
  614. result_device_id.device_type = DEVICE_TYPE_DFP;
  615. result_device_id.enum_id = 6;
  616. break;
  617. default:
  618. BREAK_TO_DEBUGGER(); /* Invalid device Id */
  619. result_device_id.device_type = DEVICE_TYPE_UNKNOWN;
  620. result_device_id.enum_id = 0;
  621. }
  622. return result_device_id;
  623. }
  624. static enum bp_result bios_parser_get_device_tag(
  625. struct dc_bios *dcb,
  626. struct graphics_object_id connector_object_id,
  627. uint32_t device_tag_index,
  628. struct connector_device_tag_info *info)
  629. {
  630. struct bios_parser *bp = BP_FROM_DCB(dcb);
  631. struct atom_display_object_path_v2 *object;
  632. if (!info)
  633. return BP_RESULT_BADINPUT;
  634. /* getBiosObject will return MXM object */
  635. object = get_bios_object(bp, connector_object_id);
  636. if (!object) {
  637. BREAK_TO_DEBUGGER(); /* Invalid object id */
  638. return BP_RESULT_BADINPUT;
  639. }
  640. info->acpi_device = 0; /* BIOS no longer provides this */
  641. info->dev_id = device_type_from_device_id(object->device_tag);
  642. return BP_RESULT_OK;
  643. }
  644. static enum bp_result get_ss_info_v4_1(
  645. struct bios_parser *bp,
  646. uint32_t id,
  647. uint32_t index,
  648. struct spread_spectrum_info *ss_info)
  649. {
  650. enum bp_result result = BP_RESULT_OK;
  651. struct atom_display_controller_info_v4_1 *disp_cntl_tbl = NULL;
  652. if (!ss_info)
  653. return BP_RESULT_BADINPUT;
  654. if (!DATA_TABLES(dce_info))
  655. return BP_RESULT_BADBIOSTABLE;
  656. disp_cntl_tbl = GET_IMAGE(struct atom_display_controller_info_v4_1,
  657. DATA_TABLES(dce_info));
  658. if (!disp_cntl_tbl)
  659. return BP_RESULT_BADBIOSTABLE;
  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. switch (id) {
  665. case AS_SIGNAL_TYPE_DVI:
  666. ss_info->spread_spectrum_percentage =
  667. disp_cntl_tbl->dvi_ss_percentage;
  668. ss_info->spread_spectrum_range =
  669. disp_cntl_tbl->dvi_ss_rate_10hz * 10;
  670. if (disp_cntl_tbl->dvi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
  671. ss_info->type.CENTER_MODE = true;
  672. break;
  673. case AS_SIGNAL_TYPE_HDMI:
  674. ss_info->spread_spectrum_percentage =
  675. disp_cntl_tbl->hdmi_ss_percentage;
  676. ss_info->spread_spectrum_range =
  677. disp_cntl_tbl->hdmi_ss_rate_10hz * 10;
  678. if (disp_cntl_tbl->hdmi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
  679. ss_info->type.CENTER_MODE = true;
  680. break;
  681. /* TODO LVDS not support anymore? */
  682. case AS_SIGNAL_TYPE_DISPLAY_PORT:
  683. ss_info->spread_spectrum_percentage =
  684. disp_cntl_tbl->dp_ss_percentage;
  685. ss_info->spread_spectrum_range =
  686. disp_cntl_tbl->dp_ss_rate_10hz * 10;
  687. if (disp_cntl_tbl->dp_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
  688. ss_info->type.CENTER_MODE = true;
  689. break;
  690. case AS_SIGNAL_TYPE_GPU_PLL:
  691. /* atom_firmware: DAL only get data from dce_info table.
  692. * if data within smu_info is needed for DAL, VBIOS should
  693. * copy it into dce_info
  694. */
  695. result = BP_RESULT_UNSUPPORTED;
  696. break;
  697. default:
  698. result = BP_RESULT_UNSUPPORTED;
  699. }
  700. return result;
  701. }
  702. static enum bp_result get_ss_info_v4_2(
  703. struct bios_parser *bp,
  704. uint32_t id,
  705. uint32_t index,
  706. struct spread_spectrum_info *ss_info)
  707. {
  708. enum bp_result result = BP_RESULT_OK;
  709. struct atom_display_controller_info_v4_2 *disp_cntl_tbl = NULL;
  710. struct atom_smu_info_v3_1 *smu_info = NULL;
  711. if (!ss_info)
  712. return BP_RESULT_BADINPUT;
  713. if (!DATA_TABLES(dce_info))
  714. return BP_RESULT_BADBIOSTABLE;
  715. if (!DATA_TABLES(smu_info))
  716. return BP_RESULT_BADBIOSTABLE;
  717. disp_cntl_tbl = GET_IMAGE(struct atom_display_controller_info_v4_2,
  718. DATA_TABLES(dce_info));
  719. if (!disp_cntl_tbl)
  720. return BP_RESULT_BADBIOSTABLE;
  721. smu_info = GET_IMAGE(struct atom_smu_info_v3_1, DATA_TABLES(smu_info));
  722. if (!smu_info)
  723. return BP_RESULT_BADBIOSTABLE;
  724. ss_info->type.STEP_AND_DELAY_INFO = false;
  725. ss_info->spread_percentage_divider = 1000;
  726. /* BIOS no longer uses target clock. Always enable for now */
  727. ss_info->target_clock_range = 0xffffffff;
  728. switch (id) {
  729. case AS_SIGNAL_TYPE_DVI:
  730. ss_info->spread_spectrum_percentage =
  731. disp_cntl_tbl->dvi_ss_percentage;
  732. ss_info->spread_spectrum_range =
  733. disp_cntl_tbl->dvi_ss_rate_10hz * 10;
  734. if (disp_cntl_tbl->dvi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
  735. ss_info->type.CENTER_MODE = true;
  736. break;
  737. case AS_SIGNAL_TYPE_HDMI:
  738. ss_info->spread_spectrum_percentage =
  739. disp_cntl_tbl->hdmi_ss_percentage;
  740. ss_info->spread_spectrum_range =
  741. disp_cntl_tbl->hdmi_ss_rate_10hz * 10;
  742. if (disp_cntl_tbl->hdmi_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
  743. ss_info->type.CENTER_MODE = true;
  744. break;
  745. /* TODO LVDS not support anymore? */
  746. case AS_SIGNAL_TYPE_DISPLAY_PORT:
  747. ss_info->spread_spectrum_percentage =
  748. smu_info->gpuclk_ss_percentage;
  749. ss_info->spread_spectrum_range =
  750. smu_info->gpuclk_ss_rate_10hz * 10;
  751. if (smu_info->gpuclk_ss_mode & ATOM_SS_CENTRE_SPREAD_MODE)
  752. ss_info->type.CENTER_MODE = true;
  753. break;
  754. case AS_SIGNAL_TYPE_GPU_PLL:
  755. /* atom_firmware: DAL only get data from dce_info table.
  756. * if data within smu_info is needed for DAL, VBIOS should
  757. * copy it into dce_info
  758. */
  759. result = BP_RESULT_UNSUPPORTED;
  760. break;
  761. default:
  762. result = BP_RESULT_UNSUPPORTED;
  763. }
  764. return result;
  765. }
  766. /**
  767. * bios_parser_get_spread_spectrum_info
  768. * Get spread spectrum information from the ASIC_InternalSS_Info(ver 2.1 or
  769. * ver 3.1) or SS_Info table from the VBIOS. Currently ASIC_InternalSS_Info
  770. * ver 2.1 can co-exist with SS_Info table. Expect ASIC_InternalSS_Info
  771. * ver 3.1,
  772. * there is only one entry for each signal /ss id. However, there is
  773. * no planning of supporting multiple spread Sprectum entry for EverGreen
  774. * @param [in] this
  775. * @param [in] signal, ASSignalType to be converted to info index
  776. * @param [in] index, number of entries that match the converted info index
  777. * @param [out] ss_info, sprectrum information structure,
  778. * @return Bios parser result code
  779. */
  780. static enum bp_result bios_parser_get_spread_spectrum_info(
  781. struct dc_bios *dcb,
  782. enum as_signal_type signal,
  783. uint32_t index,
  784. struct spread_spectrum_info *ss_info)
  785. {
  786. struct bios_parser *bp = BP_FROM_DCB(dcb);
  787. enum bp_result result = BP_RESULT_UNSUPPORTED;
  788. struct atom_common_table_header *header;
  789. struct atom_data_revision tbl_revision;
  790. if (!ss_info) /* check for bad input */
  791. return BP_RESULT_BADINPUT;
  792. if (!DATA_TABLES(dce_info))
  793. return BP_RESULT_UNSUPPORTED;
  794. header = GET_IMAGE(struct atom_common_table_header,
  795. DATA_TABLES(dce_info));
  796. get_atom_data_table_revision(header, &tbl_revision);
  797. switch (tbl_revision.major) {
  798. case 4:
  799. switch (tbl_revision.minor) {
  800. case 1:
  801. return get_ss_info_v4_1(bp, signal, index, ss_info);
  802. case 2:
  803. return get_ss_info_v4_2(bp, signal, index, ss_info);
  804. default:
  805. break;
  806. }
  807. break;
  808. default:
  809. break;
  810. }
  811. /* there can not be more then one entry for SS Info table */
  812. return result;
  813. }
  814. static enum bp_result get_embedded_panel_info_v2_1(
  815. struct bios_parser *bp,
  816. struct embedded_panel_info *info)
  817. {
  818. struct lcd_info_v2_1 *lvds;
  819. if (!info)
  820. return BP_RESULT_BADINPUT;
  821. if (!DATA_TABLES(lcd_info))
  822. return BP_RESULT_UNSUPPORTED;
  823. lvds = GET_IMAGE(struct lcd_info_v2_1, DATA_TABLES(lcd_info));
  824. if (!lvds)
  825. return BP_RESULT_BADBIOSTABLE;
  826. /* TODO: previous vv1_3, should v2_1 */
  827. if (!((lvds->table_header.format_revision == 2)
  828. && (lvds->table_header.content_revision >= 1)))
  829. return BP_RESULT_UNSUPPORTED;
  830. memset(info, 0, sizeof(struct embedded_panel_info));
  831. /* We need to convert from 10KHz units into KHz units */
  832. info->lcd_timing.pixel_clk =
  833. le16_to_cpu(lvds->lcd_timing.pixclk) * 10;
  834. /* usHActive does not include borders, according to VBIOS team */
  835. info->lcd_timing.horizontal_addressable =
  836. le16_to_cpu(lvds->lcd_timing.h_active);
  837. /* usHBlanking_Time includes borders, so we should really be
  838. * subtractingborders duing this translation, but LVDS generally
  839. * doesn't have borders, so we should be okay leaving this as is for
  840. * now. May need to revisit if we ever have LVDS with borders
  841. */
  842. info->lcd_timing.horizontal_blanking_time =
  843. le16_to_cpu(lvds->lcd_timing.h_blanking_time);
  844. /* usVActive does not include borders, according to VBIOS team*/
  845. info->lcd_timing.vertical_addressable =
  846. le16_to_cpu(lvds->lcd_timing.v_active);
  847. /* usVBlanking_Time includes borders, so we should really be
  848. * subtracting borders duing this translation, but LVDS generally
  849. * doesn't have borders, so we should be okay leaving this as is for
  850. * now. May need to revisit if we ever have LVDS with borders
  851. */
  852. info->lcd_timing.vertical_blanking_time =
  853. le16_to_cpu(lvds->lcd_timing.v_blanking_time);
  854. info->lcd_timing.horizontal_sync_offset =
  855. le16_to_cpu(lvds->lcd_timing.h_sync_offset);
  856. info->lcd_timing.horizontal_sync_width =
  857. le16_to_cpu(lvds->lcd_timing.h_sync_width);
  858. info->lcd_timing.vertical_sync_offset =
  859. le16_to_cpu(lvds->lcd_timing.v_sync_offset);
  860. info->lcd_timing.vertical_sync_width =
  861. le16_to_cpu(lvds->lcd_timing.v_syncwidth);
  862. info->lcd_timing.horizontal_border = lvds->lcd_timing.h_border;
  863. info->lcd_timing.vertical_border = lvds->lcd_timing.v_border;
  864. /* not provided by VBIOS */
  865. info->lcd_timing.misc_info.HORIZONTAL_CUT_OFF = 0;
  866. info->lcd_timing.misc_info.H_SYNC_POLARITY =
  867. ~(uint32_t)
  868. (lvds->lcd_timing.miscinfo & ATOM_HSYNC_POLARITY);
  869. info->lcd_timing.misc_info.V_SYNC_POLARITY =
  870. ~(uint32_t)
  871. (lvds->lcd_timing.miscinfo & ATOM_VSYNC_POLARITY);
  872. /* not provided by VBIOS */
  873. info->lcd_timing.misc_info.VERTICAL_CUT_OFF = 0;
  874. info->lcd_timing.misc_info.H_REPLICATION_BY2 =
  875. !!(lvds->lcd_timing.miscinfo & ATOM_H_REPLICATIONBY2);
  876. info->lcd_timing.misc_info.V_REPLICATION_BY2 =
  877. !!(lvds->lcd_timing.miscinfo & ATOM_V_REPLICATIONBY2);
  878. info->lcd_timing.misc_info.COMPOSITE_SYNC =
  879. !!(lvds->lcd_timing.miscinfo & ATOM_COMPOSITESYNC);
  880. info->lcd_timing.misc_info.INTERLACE =
  881. !!(lvds->lcd_timing.miscinfo & ATOM_INTERLACE);
  882. /* not provided by VBIOS*/
  883. info->lcd_timing.misc_info.DOUBLE_CLOCK = 0;
  884. /* not provided by VBIOS*/
  885. info->ss_id = 0;
  886. info->realtek_eDPToLVDS =
  887. !!(lvds->dplvdsrxid == eDP_TO_LVDS_REALTEK_ID);
  888. return BP_RESULT_OK;
  889. }
  890. static enum bp_result bios_parser_get_embedded_panel_info(
  891. struct dc_bios *dcb,
  892. struct embedded_panel_info *info)
  893. {
  894. struct bios_parser *bp = BP_FROM_DCB(dcb);
  895. struct atom_common_table_header *header;
  896. struct atom_data_revision tbl_revision;
  897. if (!DATA_TABLES(lcd_info))
  898. return BP_RESULT_FAILURE;
  899. header = GET_IMAGE(struct atom_common_table_header,
  900. DATA_TABLES(lcd_info));
  901. if (!header)
  902. return BP_RESULT_BADBIOSTABLE;
  903. get_atom_data_table_revision(header, &tbl_revision);
  904. switch (tbl_revision.major) {
  905. case 2:
  906. switch (tbl_revision.minor) {
  907. case 1:
  908. return get_embedded_panel_info_v2_1(bp, info);
  909. default:
  910. break;
  911. }
  912. default:
  913. break;
  914. }
  915. return BP_RESULT_FAILURE;
  916. }
  917. static uint32_t get_support_mask_for_device_id(struct device_id device_id)
  918. {
  919. enum dal_device_type device_type = device_id.device_type;
  920. uint32_t enum_id = device_id.enum_id;
  921. switch (device_type) {
  922. case DEVICE_TYPE_LCD:
  923. switch (enum_id) {
  924. case 1:
  925. return ATOM_DISPLAY_LCD1_SUPPORT;
  926. default:
  927. break;
  928. }
  929. break;
  930. case DEVICE_TYPE_DFP:
  931. switch (enum_id) {
  932. case 1:
  933. return ATOM_DISPLAY_DFP1_SUPPORT;
  934. case 2:
  935. return ATOM_DISPLAY_DFP2_SUPPORT;
  936. case 3:
  937. return ATOM_DISPLAY_DFP3_SUPPORT;
  938. case 4:
  939. return ATOM_DISPLAY_DFP4_SUPPORT;
  940. case 5:
  941. return ATOM_DISPLAY_DFP5_SUPPORT;
  942. case 6:
  943. return ATOM_DISPLAY_DFP6_SUPPORT;
  944. default:
  945. break;
  946. }
  947. break;
  948. default:
  949. break;
  950. };
  951. /* Unidentified device ID, return empty support mask. */
  952. return 0;
  953. }
  954. static bool bios_parser_is_device_id_supported(
  955. struct dc_bios *dcb,
  956. struct device_id id)
  957. {
  958. struct bios_parser *bp = BP_FROM_DCB(dcb);
  959. uint32_t mask = get_support_mask_for_device_id(id);
  960. return (le16_to_cpu(bp->object_info_tbl.v1_4->supporteddevices) &
  961. mask) != 0;
  962. }
  963. static void bios_parser_post_init(
  964. struct dc_bios *dcb)
  965. {
  966. /* TODO for OPM module. Need implement later */
  967. }
  968. static uint32_t bios_parser_get_ss_entry_number(
  969. struct dc_bios *dcb,
  970. enum as_signal_type signal)
  971. {
  972. /* TODO: DAL2 atomfirmware implementation does not need this.
  973. * why DAL3 need this?
  974. */
  975. return 1;
  976. }
  977. static enum bp_result bios_parser_transmitter_control(
  978. struct dc_bios *dcb,
  979. struct bp_transmitter_control *cntl)
  980. {
  981. struct bios_parser *bp = BP_FROM_DCB(dcb);
  982. if (!bp->cmd_tbl.transmitter_control)
  983. return BP_RESULT_FAILURE;
  984. return bp->cmd_tbl.transmitter_control(bp, cntl);
  985. }
  986. static enum bp_result bios_parser_encoder_control(
  987. struct dc_bios *dcb,
  988. struct bp_encoder_control *cntl)
  989. {
  990. struct bios_parser *bp = BP_FROM_DCB(dcb);
  991. if (!bp->cmd_tbl.dig_encoder_control)
  992. return BP_RESULT_FAILURE;
  993. return bp->cmd_tbl.dig_encoder_control(bp, cntl);
  994. }
  995. static enum bp_result bios_parser_set_pixel_clock(
  996. struct dc_bios *dcb,
  997. struct bp_pixel_clock_parameters *bp_params)
  998. {
  999. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1000. if (!bp->cmd_tbl.set_pixel_clock)
  1001. return BP_RESULT_FAILURE;
  1002. return bp->cmd_tbl.set_pixel_clock(bp, bp_params);
  1003. }
  1004. static enum bp_result bios_parser_set_dce_clock(
  1005. struct dc_bios *dcb,
  1006. struct bp_set_dce_clock_parameters *bp_params)
  1007. {
  1008. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1009. if (!bp->cmd_tbl.set_dce_clock)
  1010. return BP_RESULT_FAILURE;
  1011. return bp->cmd_tbl.set_dce_clock(bp, bp_params);
  1012. }
  1013. static unsigned int bios_parser_get_smu_clock_info(
  1014. struct dc_bios *dcb)
  1015. {
  1016. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1017. if (!bp->cmd_tbl.get_smu_clock_info)
  1018. return BP_RESULT_FAILURE;
  1019. return bp->cmd_tbl.get_smu_clock_info(bp, 0);
  1020. }
  1021. static enum bp_result bios_parser_program_crtc_timing(
  1022. struct dc_bios *dcb,
  1023. struct bp_hw_crtc_timing_parameters *bp_params)
  1024. {
  1025. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1026. if (!bp->cmd_tbl.set_crtc_timing)
  1027. return BP_RESULT_FAILURE;
  1028. return bp->cmd_tbl.set_crtc_timing(bp, bp_params);
  1029. }
  1030. static enum bp_result bios_parser_enable_crtc(
  1031. struct dc_bios *dcb,
  1032. enum controller_id id,
  1033. bool enable)
  1034. {
  1035. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1036. if (!bp->cmd_tbl.enable_crtc)
  1037. return BP_RESULT_FAILURE;
  1038. return bp->cmd_tbl.enable_crtc(bp, id, enable);
  1039. }
  1040. static enum bp_result bios_parser_crtc_source_select(
  1041. struct dc_bios *dcb,
  1042. struct bp_crtc_source_select *bp_params)
  1043. {
  1044. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1045. if (!bp->cmd_tbl.select_crtc_source)
  1046. return BP_RESULT_FAILURE;
  1047. return bp->cmd_tbl.select_crtc_source(bp, bp_params);
  1048. }
  1049. static enum bp_result bios_parser_enable_disp_power_gating(
  1050. struct dc_bios *dcb,
  1051. enum controller_id controller_id,
  1052. enum bp_pipe_control_action action)
  1053. {
  1054. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1055. if (!bp->cmd_tbl.enable_disp_power_gating)
  1056. return BP_RESULT_FAILURE;
  1057. return bp->cmd_tbl.enable_disp_power_gating(bp, controller_id,
  1058. action);
  1059. }
  1060. static bool bios_parser_is_accelerated_mode(
  1061. struct dc_bios *dcb)
  1062. {
  1063. return bios_is_accelerated_mode(dcb);
  1064. }
  1065. static uint32_t bios_parser_get_vga_enabled_displays(
  1066. struct dc_bios *bios)
  1067. {
  1068. return bios_get_vga_enabled_displays(bios);
  1069. }
  1070. /**
  1071. * bios_parser_set_scratch_critical_state
  1072. *
  1073. * @brief
  1074. * update critical state bit in VBIOS scratch register
  1075. *
  1076. * @param
  1077. * bool - to set or reset state
  1078. */
  1079. static void bios_parser_set_scratch_critical_state(
  1080. struct dc_bios *dcb,
  1081. bool state)
  1082. {
  1083. bios_set_scratch_critical_state(dcb, state);
  1084. }
  1085. static enum bp_result bios_parser_get_firmware_info(
  1086. struct dc_bios *dcb,
  1087. struct dc_firmware_info *info)
  1088. {
  1089. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1090. enum bp_result result = BP_RESULT_BADBIOSTABLE;
  1091. struct atom_common_table_header *header;
  1092. struct atom_data_revision revision;
  1093. if (info && DATA_TABLES(firmwareinfo)) {
  1094. header = GET_IMAGE(struct atom_common_table_header,
  1095. DATA_TABLES(firmwareinfo));
  1096. get_atom_data_table_revision(header, &revision);
  1097. switch (revision.major) {
  1098. case 3:
  1099. switch (revision.minor) {
  1100. case 1:
  1101. case 2:
  1102. result = get_firmware_info_v3_1(bp, info);
  1103. break;
  1104. default:
  1105. break;
  1106. }
  1107. break;
  1108. default:
  1109. break;
  1110. }
  1111. }
  1112. return result;
  1113. }
  1114. static enum bp_result get_firmware_info_v3_1(
  1115. struct bios_parser *bp,
  1116. struct dc_firmware_info *info)
  1117. {
  1118. struct atom_firmware_info_v3_1 *firmware_info;
  1119. struct atom_display_controller_info_v4_1 *dce_info = NULL;
  1120. if (!info)
  1121. return BP_RESULT_BADINPUT;
  1122. firmware_info = GET_IMAGE(struct atom_firmware_info_v3_1,
  1123. DATA_TABLES(firmwareinfo));
  1124. dce_info = GET_IMAGE(struct atom_display_controller_info_v4_1,
  1125. DATA_TABLES(dce_info));
  1126. if (!firmware_info || !dce_info)
  1127. return BP_RESULT_BADBIOSTABLE;
  1128. memset(info, 0, sizeof(*info));
  1129. /* Pixel clock pll information. */
  1130. /* We need to convert from 10KHz units into KHz units */
  1131. info->default_memory_clk = firmware_info->bootup_mclk_in10khz * 10;
  1132. info->default_engine_clk = firmware_info->bootup_sclk_in10khz * 10;
  1133. /* 27MHz for Vega10: */
  1134. info->pll_info.crystal_frequency = dce_info->dce_refclk_10khz * 10;
  1135. /* Hardcode frequency if BIOS gives no DCE Ref Clk */
  1136. if (info->pll_info.crystal_frequency == 0)
  1137. info->pll_info.crystal_frequency = 27000;
  1138. /*dp_phy_ref_clk is not correct for atom_display_controller_info_v4_2, but we don't use it*/
  1139. info->dp_phy_ref_clk = dce_info->dpphy_refclk_10khz * 10;
  1140. info->i2c_engine_ref_clk = dce_info->i2c_engine_refclk_10khz * 10;
  1141. /* Get GPU PLL VCO Clock */
  1142. if (bp->cmd_tbl.get_smu_clock_info != NULL) {
  1143. /* VBIOS gives in 10KHz */
  1144. info->smu_gpu_pll_output_freq =
  1145. bp->cmd_tbl.get_smu_clock_info(bp, SMU9_SYSPLL0_ID) * 10;
  1146. }
  1147. return BP_RESULT_OK;
  1148. }
  1149. static enum bp_result bios_parser_get_encoder_cap_info(
  1150. struct dc_bios *dcb,
  1151. struct graphics_object_id object_id,
  1152. struct bp_encoder_cap_info *info)
  1153. {
  1154. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1155. struct atom_display_object_path_v2 *object;
  1156. struct atom_encoder_caps_record *record = NULL;
  1157. if (!info)
  1158. return BP_RESULT_BADINPUT;
  1159. object = get_bios_object(bp, object_id);
  1160. if (!object)
  1161. return BP_RESULT_BADINPUT;
  1162. record = get_encoder_cap_record(bp, object);
  1163. if (!record)
  1164. return BP_RESULT_NORECORD;
  1165. info->DP_HBR2_CAP = (record->encodercaps &
  1166. ATOM_ENCODER_CAP_RECORD_HBR2) ? 1 : 0;
  1167. info->DP_HBR2_EN = (record->encodercaps &
  1168. ATOM_ENCODER_CAP_RECORD_HBR2_EN) ? 1 : 0;
  1169. info->DP_HBR3_EN = (record->encodercaps &
  1170. ATOM_ENCODER_CAP_RECORD_HBR3_EN) ? 1 : 0;
  1171. info->HDMI_6GB_EN = (record->encodercaps &
  1172. ATOM_ENCODER_CAP_RECORD_HDMI6Gbps_EN) ? 1 : 0;
  1173. return BP_RESULT_OK;
  1174. }
  1175. static struct atom_encoder_caps_record *get_encoder_cap_record(
  1176. struct bios_parser *bp,
  1177. struct atom_display_object_path_v2 *object)
  1178. {
  1179. struct atom_common_record_header *header;
  1180. uint32_t offset;
  1181. if (!object) {
  1182. BREAK_TO_DEBUGGER(); /* Invalid object */
  1183. return NULL;
  1184. }
  1185. offset = object->encoder_recordoffset + bp->object_info_tbl_offset;
  1186. for (;;) {
  1187. header = GET_IMAGE(struct atom_common_record_header, offset);
  1188. if (!header)
  1189. return NULL;
  1190. offset += header->record_size;
  1191. if (header->record_type == LAST_RECORD_TYPE ||
  1192. !header->record_size)
  1193. break;
  1194. if (header->record_type != ATOM_ENCODER_CAP_RECORD_TYPE)
  1195. continue;
  1196. if (sizeof(struct atom_encoder_caps_record) <=
  1197. header->record_size)
  1198. return (struct atom_encoder_caps_record *)header;
  1199. }
  1200. return NULL;
  1201. }
  1202. /*
  1203. * get_integrated_info_v11
  1204. *
  1205. * @brief
  1206. * Get V8 integrated BIOS information
  1207. *
  1208. * @param
  1209. * bios_parser *bp - [in]BIOS parser handler to get master data table
  1210. * integrated_info *info - [out] store and output integrated info
  1211. *
  1212. * @return
  1213. * enum bp_result - BP_RESULT_OK if information is available,
  1214. * BP_RESULT_BADBIOSTABLE otherwise.
  1215. */
  1216. static enum bp_result get_integrated_info_v11(
  1217. struct bios_parser *bp,
  1218. struct integrated_info *info)
  1219. {
  1220. struct atom_integrated_system_info_v1_11 *info_v11;
  1221. uint32_t i;
  1222. info_v11 = GET_IMAGE(struct atom_integrated_system_info_v1_11,
  1223. DATA_TABLES(integratedsysteminfo));
  1224. if (info_v11 == NULL)
  1225. return BP_RESULT_BADBIOSTABLE;
  1226. info->gpu_cap_info =
  1227. le32_to_cpu(info_v11->gpucapinfo);
  1228. /*
  1229. * system_config: Bit[0] = 0 : PCIE power gating disabled
  1230. * = 1 : PCIE power gating enabled
  1231. * Bit[1] = 0 : DDR-PLL shut down disabled
  1232. * = 1 : DDR-PLL shut down enabled
  1233. * Bit[2] = 0 : DDR-PLL power down disabled
  1234. * = 1 : DDR-PLL power down enabled
  1235. */
  1236. info->system_config = le32_to_cpu(info_v11->system_config);
  1237. info->cpu_cap_info = le32_to_cpu(info_v11->cpucapinfo);
  1238. info->memory_type = info_v11->memorytype;
  1239. info->ma_channel_number = info_v11->umachannelnumber;
  1240. info->lvds_ss_percentage =
  1241. le16_to_cpu(info_v11->lvds_ss_percentage);
  1242. info->lvds_sspread_rate_in_10hz =
  1243. le16_to_cpu(info_v11->lvds_ss_rate_10hz);
  1244. info->hdmi_ss_percentage =
  1245. le16_to_cpu(info_v11->hdmi_ss_percentage);
  1246. info->hdmi_sspread_rate_in_10hz =
  1247. le16_to_cpu(info_v11->hdmi_ss_rate_10hz);
  1248. info->dvi_ss_percentage =
  1249. le16_to_cpu(info_v11->dvi_ss_percentage);
  1250. info->dvi_sspread_rate_in_10_hz =
  1251. le16_to_cpu(info_v11->dvi_ss_rate_10hz);
  1252. info->lvds_misc = info_v11->lvds_misc;
  1253. for (i = 0; i < NUMBER_OF_UCHAR_FOR_GUID; ++i) {
  1254. info->ext_disp_conn_info.gu_id[i] =
  1255. info_v11->extdispconninfo.guid[i];
  1256. }
  1257. for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; ++i) {
  1258. info->ext_disp_conn_info.path[i].device_connector_id =
  1259. object_id_from_bios_object_id(
  1260. le16_to_cpu(info_v11->extdispconninfo.path[i].connectorobjid));
  1261. info->ext_disp_conn_info.path[i].ext_encoder_obj_id =
  1262. object_id_from_bios_object_id(
  1263. le16_to_cpu(
  1264. info_v11->extdispconninfo.path[i].ext_encoder_objid));
  1265. info->ext_disp_conn_info.path[i].device_tag =
  1266. le16_to_cpu(
  1267. info_v11->extdispconninfo.path[i].device_tag);
  1268. info->ext_disp_conn_info.path[i].device_acpi_enum =
  1269. le16_to_cpu(
  1270. info_v11->extdispconninfo.path[i].device_acpi_enum);
  1271. info->ext_disp_conn_info.path[i].ext_aux_ddc_lut_index =
  1272. info_v11->extdispconninfo.path[i].auxddclut_index;
  1273. info->ext_disp_conn_info.path[i].ext_hpd_pin_lut_index =
  1274. info_v11->extdispconninfo.path[i].hpdlut_index;
  1275. info->ext_disp_conn_info.path[i].channel_mapping.raw =
  1276. info_v11->extdispconninfo.path[i].channelmapping;
  1277. info->ext_disp_conn_info.path[i].caps =
  1278. le16_to_cpu(info_v11->extdispconninfo.path[i].caps);
  1279. }
  1280. info->ext_disp_conn_info.checksum =
  1281. info_v11->extdispconninfo.checksum;
  1282. info->dp0_ext_hdmi_slv_addr = info_v11->dp0_retimer_set.HdmiSlvAddr;
  1283. info->dp0_ext_hdmi_reg_num = info_v11->dp0_retimer_set.HdmiRegNum;
  1284. for (i = 0; i < info->dp0_ext_hdmi_reg_num; i++) {
  1285. info->dp0_ext_hdmi_reg_settings[i].i2c_reg_index =
  1286. info_v11->dp0_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
  1287. info->dp0_ext_hdmi_reg_settings[i].i2c_reg_val =
  1288. info_v11->dp0_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
  1289. }
  1290. info->dp0_ext_hdmi_6g_reg_num = info_v11->dp0_retimer_set.Hdmi6GRegNum;
  1291. for (i = 0; i < info->dp0_ext_hdmi_6g_reg_num; i++) {
  1292. info->dp0_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
  1293. info_v11->dp0_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
  1294. info->dp0_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
  1295. info_v11->dp0_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
  1296. }
  1297. info->dp1_ext_hdmi_slv_addr = info_v11->dp1_retimer_set.HdmiSlvAddr;
  1298. info->dp1_ext_hdmi_reg_num = info_v11->dp1_retimer_set.HdmiRegNum;
  1299. for (i = 0; i < info->dp1_ext_hdmi_reg_num; i++) {
  1300. info->dp1_ext_hdmi_reg_settings[i].i2c_reg_index =
  1301. info_v11->dp1_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
  1302. info->dp1_ext_hdmi_reg_settings[i].i2c_reg_val =
  1303. info_v11->dp1_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
  1304. }
  1305. info->dp1_ext_hdmi_6g_reg_num = info_v11->dp1_retimer_set.Hdmi6GRegNum;
  1306. for (i = 0; i < info->dp1_ext_hdmi_6g_reg_num; i++) {
  1307. info->dp1_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
  1308. info_v11->dp1_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
  1309. info->dp1_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
  1310. info_v11->dp1_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
  1311. }
  1312. info->dp2_ext_hdmi_slv_addr = info_v11->dp2_retimer_set.HdmiSlvAddr;
  1313. info->dp2_ext_hdmi_reg_num = info_v11->dp2_retimer_set.HdmiRegNum;
  1314. for (i = 0; i < info->dp2_ext_hdmi_reg_num; i++) {
  1315. info->dp2_ext_hdmi_reg_settings[i].i2c_reg_index =
  1316. info_v11->dp2_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
  1317. info->dp2_ext_hdmi_reg_settings[i].i2c_reg_val =
  1318. info_v11->dp2_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
  1319. }
  1320. info->dp2_ext_hdmi_6g_reg_num = info_v11->dp2_retimer_set.Hdmi6GRegNum;
  1321. for (i = 0; i < info->dp2_ext_hdmi_6g_reg_num; i++) {
  1322. info->dp2_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
  1323. info_v11->dp2_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
  1324. info->dp2_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
  1325. info_v11->dp2_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
  1326. }
  1327. info->dp3_ext_hdmi_slv_addr = info_v11->dp3_retimer_set.HdmiSlvAddr;
  1328. info->dp3_ext_hdmi_reg_num = info_v11->dp3_retimer_set.HdmiRegNum;
  1329. for (i = 0; i < info->dp3_ext_hdmi_reg_num; i++) {
  1330. info->dp3_ext_hdmi_reg_settings[i].i2c_reg_index =
  1331. info_v11->dp3_retimer_set.HdmiRegSetting[i].ucI2cRegIndex;
  1332. info->dp3_ext_hdmi_reg_settings[i].i2c_reg_val =
  1333. info_v11->dp3_retimer_set.HdmiRegSetting[i].ucI2cRegVal;
  1334. }
  1335. info->dp3_ext_hdmi_6g_reg_num = info_v11->dp3_retimer_set.Hdmi6GRegNum;
  1336. for (i = 0; i < info->dp3_ext_hdmi_6g_reg_num; i++) {
  1337. info->dp3_ext_hdmi_6g_reg_settings[i].i2c_reg_index =
  1338. info_v11->dp3_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegIndex;
  1339. info->dp3_ext_hdmi_6g_reg_settings[i].i2c_reg_val =
  1340. info_v11->dp3_retimer_set.Hdmi6GhzRegSetting[i].ucI2cRegVal;
  1341. }
  1342. /** TODO - review **/
  1343. #if 0
  1344. info->boot_up_engine_clock = le32_to_cpu(info_v11->ulBootUpEngineClock)
  1345. * 10;
  1346. info->dentist_vco_freq = le32_to_cpu(info_v11->ulDentistVCOFreq) * 10;
  1347. info->boot_up_uma_clock = le32_to_cpu(info_v8->ulBootUpUMAClock) * 10;
  1348. for (i = 0; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
  1349. /* Convert [10KHz] into [KHz] */
  1350. info->disp_clk_voltage[i].max_supported_clk =
  1351. le32_to_cpu(info_v11->sDISPCLK_Voltage[i].
  1352. ulMaximumSupportedCLK) * 10;
  1353. info->disp_clk_voltage[i].voltage_index =
  1354. le32_to_cpu(info_v11->sDISPCLK_Voltage[i].ulVoltageIndex);
  1355. }
  1356. info->boot_up_req_display_vector =
  1357. le32_to_cpu(info_v11->ulBootUpReqDisplayVector);
  1358. info->boot_up_nb_voltage =
  1359. le16_to_cpu(info_v11->usBootUpNBVoltage);
  1360. info->ext_disp_conn_info_offset =
  1361. le16_to_cpu(info_v11->usExtDispConnInfoOffset);
  1362. info->gmc_restore_reset_time =
  1363. le32_to_cpu(info_v11->ulGMCRestoreResetTime);
  1364. info->minimum_n_clk =
  1365. le32_to_cpu(info_v11->ulNbpStateNClkFreq[0]);
  1366. for (i = 1; i < 4; ++i)
  1367. info->minimum_n_clk =
  1368. info->minimum_n_clk <
  1369. le32_to_cpu(info_v11->ulNbpStateNClkFreq[i]) ?
  1370. info->minimum_n_clk : le32_to_cpu(
  1371. info_v11->ulNbpStateNClkFreq[i]);
  1372. info->idle_n_clk = le32_to_cpu(info_v11->ulIdleNClk);
  1373. info->ddr_dll_power_up_time =
  1374. le32_to_cpu(info_v11->ulDDR_DLL_PowerUpTime);
  1375. info->ddr_pll_power_up_time =
  1376. le32_to_cpu(info_v11->ulDDR_PLL_PowerUpTime);
  1377. info->pcie_clk_ss_type = le16_to_cpu(info_v11->usPCIEClkSSType);
  1378. info->max_lvds_pclk_freq_in_single_link =
  1379. le16_to_cpu(info_v11->usMaxLVDSPclkFreqInSingleLink);
  1380. info->max_lvds_pclk_freq_in_single_link =
  1381. le16_to_cpu(info_v11->usMaxLVDSPclkFreqInSingleLink);
  1382. info->lvds_pwr_on_seq_dig_on_to_de_in_4ms =
  1383. info_v11->ucLVDSPwrOnSeqDIGONtoDE_in4Ms;
  1384. info->lvds_pwr_on_seq_de_to_vary_bl_in_4ms =
  1385. info_v11->ucLVDSPwrOnSeqDEtoVARY_BL_in4Ms;
  1386. info->lvds_pwr_on_seq_vary_bl_to_blon_in_4ms =
  1387. info_v11->ucLVDSPwrOnSeqVARY_BLtoBLON_in4Ms;
  1388. info->lvds_pwr_off_seq_vary_bl_to_de_in4ms =
  1389. info_v11->ucLVDSPwrOffSeqVARY_BLtoDE_in4Ms;
  1390. info->lvds_pwr_off_seq_de_to_dig_on_in4ms =
  1391. info_v11->ucLVDSPwrOffSeqDEtoDIGON_in4Ms;
  1392. info->lvds_pwr_off_seq_blon_to_vary_bl_in_4ms =
  1393. info_v11->ucLVDSPwrOffSeqBLONtoVARY_BL_in4Ms;
  1394. info->lvds_off_to_on_delay_in_4ms =
  1395. info_v11->ucLVDSOffToOnDelay_in4Ms;
  1396. info->lvds_bit_depth_control_val =
  1397. le32_to_cpu(info_v11->ulLCDBitDepthControlVal);
  1398. for (i = 0; i < NUMBER_OF_AVAILABLE_SCLK; ++i) {
  1399. /* Convert [10KHz] into [KHz] */
  1400. info->avail_s_clk[i].supported_s_clk =
  1401. le32_to_cpu(info_v11->sAvail_SCLK[i].ulSupportedSCLK)
  1402. * 10;
  1403. info->avail_s_clk[i].voltage_index =
  1404. le16_to_cpu(info_v11->sAvail_SCLK[i].usVoltageIndex);
  1405. info->avail_s_clk[i].voltage_id =
  1406. le16_to_cpu(info_v11->sAvail_SCLK[i].usVoltageID);
  1407. }
  1408. #endif /* TODO*/
  1409. return BP_RESULT_OK;
  1410. }
  1411. /*
  1412. * construct_integrated_info
  1413. *
  1414. * @brief
  1415. * Get integrated BIOS information based on table revision
  1416. *
  1417. * @param
  1418. * bios_parser *bp - [in]BIOS parser handler to get master data table
  1419. * integrated_info *info - [out] store and output integrated info
  1420. *
  1421. * @return
  1422. * enum bp_result - BP_RESULT_OK if information is available,
  1423. * BP_RESULT_BADBIOSTABLE otherwise.
  1424. */
  1425. static enum bp_result construct_integrated_info(
  1426. struct bios_parser *bp,
  1427. struct integrated_info *info)
  1428. {
  1429. enum bp_result result = BP_RESULT_BADBIOSTABLE;
  1430. struct atom_common_table_header *header;
  1431. struct atom_data_revision revision;
  1432. struct clock_voltage_caps temp = {0, 0};
  1433. uint32_t i;
  1434. uint32_t j;
  1435. if (info && DATA_TABLES(integratedsysteminfo)) {
  1436. header = GET_IMAGE(struct atom_common_table_header,
  1437. DATA_TABLES(integratedsysteminfo));
  1438. get_atom_data_table_revision(header, &revision);
  1439. /* Don't need to check major revision as they are all 1 */
  1440. switch (revision.minor) {
  1441. case 11:
  1442. result = get_integrated_info_v11(bp, info);
  1443. break;
  1444. default:
  1445. return result;
  1446. }
  1447. }
  1448. if (result != BP_RESULT_OK)
  1449. return result;
  1450. /* Sort voltage table from low to high*/
  1451. for (i = 1; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
  1452. for (j = i; j > 0; --j) {
  1453. if (info->disp_clk_voltage[j].max_supported_clk <
  1454. info->disp_clk_voltage[j-1].max_supported_clk
  1455. ) {
  1456. /* swap j and j - 1*/
  1457. temp = info->disp_clk_voltage[j-1];
  1458. info->disp_clk_voltage[j-1] =
  1459. info->disp_clk_voltage[j];
  1460. info->disp_clk_voltage[j] = temp;
  1461. }
  1462. }
  1463. }
  1464. return result;
  1465. }
  1466. static struct integrated_info *bios_parser_create_integrated_info(
  1467. struct dc_bios *dcb)
  1468. {
  1469. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1470. struct integrated_info *info = NULL;
  1471. info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);
  1472. if (info == NULL) {
  1473. ASSERT_CRITICAL(0);
  1474. return NULL;
  1475. }
  1476. if (construct_integrated_info(bp, info) == BP_RESULT_OK)
  1477. return info;
  1478. kfree(info);
  1479. return NULL;
  1480. }
  1481. static const struct dc_vbios_funcs vbios_funcs = {
  1482. .get_connectors_number = bios_parser_get_connectors_number,
  1483. .get_encoder_id = bios_parser_get_encoder_id,
  1484. .get_connector_id = bios_parser_get_connector_id,
  1485. .get_dst_number = bios_parser_get_dst_number,
  1486. .get_src_obj = bios_parser_get_src_obj,
  1487. .get_dst_obj = bios_parser_get_dst_obj,
  1488. .get_i2c_info = bios_parser_get_i2c_info,
  1489. .get_voltage_ddc_info = bios_parser_get_voltage_ddc_info,
  1490. .get_thermal_ddc_info = bios_parser_get_thermal_ddc_info,
  1491. .get_hpd_info = bios_parser_get_hpd_info,
  1492. .get_device_tag = bios_parser_get_device_tag,
  1493. .get_firmware_info = bios_parser_get_firmware_info,
  1494. .get_spread_spectrum_info = bios_parser_get_spread_spectrum_info,
  1495. .get_ss_entry_number = bios_parser_get_ss_entry_number,
  1496. .get_embedded_panel_info = bios_parser_get_embedded_panel_info,
  1497. .get_gpio_pin_info = bios_parser_get_gpio_pin_info,
  1498. .get_encoder_cap_info = bios_parser_get_encoder_cap_info,
  1499. .is_device_id_supported = bios_parser_is_device_id_supported,
  1500. .is_accelerated_mode = bios_parser_is_accelerated_mode,
  1501. .get_vga_enabled_displays = bios_parser_get_vga_enabled_displays,
  1502. .set_scratch_critical_state = bios_parser_set_scratch_critical_state,
  1503. /* COMMANDS */
  1504. .encoder_control = bios_parser_encoder_control,
  1505. .transmitter_control = bios_parser_transmitter_control,
  1506. .enable_crtc = bios_parser_enable_crtc,
  1507. .set_pixel_clock = bios_parser_set_pixel_clock,
  1508. .set_dce_clock = bios_parser_set_dce_clock,
  1509. .program_crtc_timing = bios_parser_program_crtc_timing,
  1510. /* .blank_crtc = bios_parser_blank_crtc, */
  1511. .crtc_source_select = bios_parser_crtc_source_select,
  1512. /* .external_encoder_control = bios_parser_external_encoder_control, */
  1513. .enable_disp_power_gating = bios_parser_enable_disp_power_gating,
  1514. .post_init = bios_parser_post_init,
  1515. .bios_parser_destroy = firmware_parser_destroy,
  1516. .get_smu_clock_info = bios_parser_get_smu_clock_info,
  1517. };
  1518. static bool bios_parser_construct(
  1519. struct bios_parser *bp,
  1520. struct bp_init_data *init,
  1521. enum dce_version dce_version)
  1522. {
  1523. uint16_t *rom_header_offset = NULL;
  1524. struct atom_rom_header_v2_2 *rom_header = NULL;
  1525. struct display_object_info_table_v1_4 *object_info_tbl;
  1526. struct atom_data_revision tbl_rev = {0};
  1527. if (!init)
  1528. return false;
  1529. if (!init->bios)
  1530. return false;
  1531. bp->base.funcs = &vbios_funcs;
  1532. bp->base.bios = init->bios;
  1533. bp->base.bios_size = bp->base.bios[OFFSET_TO_ATOM_ROM_IMAGE_SIZE] * BIOS_IMAGE_SIZE_UNIT;
  1534. bp->base.ctx = init->ctx;
  1535. bp->base.bios_local_image = NULL;
  1536. rom_header_offset =
  1537. GET_IMAGE(uint16_t, OFFSET_TO_ATOM_ROM_HEADER_POINTER);
  1538. if (!rom_header_offset)
  1539. return false;
  1540. rom_header = GET_IMAGE(struct atom_rom_header_v2_2, *rom_header_offset);
  1541. if (!rom_header)
  1542. return false;
  1543. get_atom_data_table_revision(&rom_header->table_header, &tbl_rev);
  1544. if (!(tbl_rev.major >= 2 && tbl_rev.minor >= 2))
  1545. return false;
  1546. bp->master_data_tbl =
  1547. GET_IMAGE(struct atom_master_data_table_v2_1,
  1548. rom_header->masterdatatable_offset);
  1549. if (!bp->master_data_tbl)
  1550. return false;
  1551. bp->object_info_tbl_offset = DATA_TABLES(displayobjectinfo);
  1552. if (!bp->object_info_tbl_offset)
  1553. return false;
  1554. object_info_tbl =
  1555. GET_IMAGE(struct display_object_info_table_v1_4,
  1556. bp->object_info_tbl_offset);
  1557. if (!object_info_tbl)
  1558. return false;
  1559. get_atom_data_table_revision(&object_info_tbl->table_header,
  1560. &bp->object_info_tbl.revision);
  1561. if (bp->object_info_tbl.revision.major == 1
  1562. && bp->object_info_tbl.revision.minor >= 4) {
  1563. struct display_object_info_table_v1_4 *tbl_v1_4;
  1564. tbl_v1_4 = GET_IMAGE(struct display_object_info_table_v1_4,
  1565. bp->object_info_tbl_offset);
  1566. if (!tbl_v1_4)
  1567. return false;
  1568. bp->object_info_tbl.v1_4 = tbl_v1_4;
  1569. } else
  1570. return false;
  1571. dal_firmware_parser_init_cmd_tbl(bp);
  1572. dal_bios_parser_init_cmd_tbl_helper2(&bp->cmd_helper, dce_version);
  1573. bp->base.integrated_info = bios_parser_create_integrated_info(&bp->base);
  1574. return true;
  1575. }
  1576. struct dc_bios *firmware_parser_create(
  1577. struct bp_init_data *init,
  1578. enum dce_version dce_version)
  1579. {
  1580. struct bios_parser *bp = NULL;
  1581. bp = kzalloc(sizeof(struct bios_parser), GFP_KERNEL);
  1582. if (!bp)
  1583. return NULL;
  1584. if (bios_parser_construct(bp, init, dce_version))
  1585. return &bp->base;
  1586. kfree(bp);
  1587. return NULL;
  1588. }