bios_parser.c 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871
  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 "atom.h"
  27. #include "dc_bios_types.h"
  28. #include "include/gpio_service_interface.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_table.h"
  34. #include "bios_parser_helper.h"
  35. #include "command_table_helper.h"
  36. #include "bios_parser.h"
  37. #include "bios_parser_types_internal.h"
  38. #include "bios_parser_interface.h"
  39. #include "bios_parser_common.h"
  40. /* TODO remove - only needed for default i2c speed */
  41. #include "dc.h"
  42. #define THREE_PERCENT_OF_10000 300
  43. #define LAST_RECORD_TYPE 0xff
  44. /* GUID to validate external display connection info table (aka OPM module) */
  45. static const uint8_t ext_display_connection_guid[NUMBER_OF_UCHAR_FOR_GUID] = {
  46. 0x91, 0x6E, 0x57, 0x09,
  47. 0x3F, 0x6D, 0xD2, 0x11,
  48. 0x39, 0x8E, 0x00, 0xA0,
  49. 0xC9, 0x69, 0x72, 0x3B};
  50. #define DATA_TABLES(table) (bp->master_data_tbl->ListOfDataTables.table)
  51. static void get_atom_data_table_revision(
  52. ATOM_COMMON_TABLE_HEADER *atom_data_tbl,
  53. struct atom_data_revision *tbl_revision);
  54. static uint32_t get_dst_number_from_object(struct bios_parser *bp,
  55. ATOM_OBJECT *object);
  56. static uint32_t get_src_obj_list(struct bios_parser *bp, ATOM_OBJECT *object,
  57. uint16_t **id_list);
  58. static uint32_t get_dest_obj_list(struct bios_parser *bp,
  59. ATOM_OBJECT *object, uint16_t **id_list);
  60. static ATOM_OBJECT *get_bios_object(struct bios_parser *bp,
  61. struct graphics_object_id id);
  62. static enum bp_result get_gpio_i2c_info(struct bios_parser *bp,
  63. ATOM_I2C_RECORD *record,
  64. struct graphics_object_i2c_info *info);
  65. static ATOM_HPD_INT_RECORD *get_hpd_record(struct bios_parser *bp,
  66. ATOM_OBJECT *object);
  67. static struct device_id device_type_from_device_id(uint16_t device_id);
  68. static uint32_t signal_to_ss_id(enum as_signal_type signal);
  69. static uint32_t get_support_mask_for_device_id(struct device_id device_id);
  70. static ATOM_ENCODER_CAP_RECORD_V2 *get_encoder_cap_record(
  71. struct bios_parser *bp,
  72. ATOM_OBJECT *object);
  73. #define BIOS_IMAGE_SIZE_OFFSET 2
  74. #define BIOS_IMAGE_SIZE_UNIT 512
  75. /*****************************************************************************/
  76. static bool bios_parser_construct(
  77. struct bios_parser *bp,
  78. struct bp_init_data *init,
  79. enum dce_version dce_version);
  80. static uint8_t bios_parser_get_connectors_number(
  81. struct dc_bios *dcb);
  82. static enum bp_result bios_parser_get_embedded_panel_info(
  83. struct dc_bios *dcb,
  84. struct embedded_panel_info *info);
  85. /*****************************************************************************/
  86. struct dc_bios *bios_parser_create(
  87. struct bp_init_data *init,
  88. enum dce_version dce_version)
  89. {
  90. struct bios_parser *bp = NULL;
  91. bp = kzalloc(sizeof(struct bios_parser), GFP_KERNEL);
  92. if (!bp)
  93. return NULL;
  94. if (bios_parser_construct(bp, init, dce_version))
  95. return &bp->base;
  96. kfree(bp);
  97. BREAK_TO_DEBUGGER();
  98. return NULL;
  99. }
  100. static void destruct(struct bios_parser *bp)
  101. {
  102. kfree(bp->base.bios_local_image);
  103. kfree(bp->base.integrated_info);
  104. }
  105. static void bios_parser_destroy(struct dc_bios **dcb)
  106. {
  107. struct bios_parser *bp = BP_FROM_DCB(*dcb);
  108. if (!bp) {
  109. BREAK_TO_DEBUGGER();
  110. return;
  111. }
  112. destruct(bp);
  113. kfree(bp);
  114. *dcb = NULL;
  115. }
  116. static uint8_t get_number_of_objects(struct bios_parser *bp, uint32_t offset)
  117. {
  118. ATOM_OBJECT_TABLE *table;
  119. uint32_t object_table_offset = bp->object_info_tbl_offset + offset;
  120. table = GET_IMAGE(ATOM_OBJECT_TABLE, object_table_offset);
  121. if (!table)
  122. return 0;
  123. else
  124. return table->ucNumberOfObjects;
  125. }
  126. static uint8_t bios_parser_get_connectors_number(struct dc_bios *dcb)
  127. {
  128. struct bios_parser *bp = BP_FROM_DCB(dcb);
  129. return get_number_of_objects(bp,
  130. le16_to_cpu(bp->object_info_tbl.v1_1->usConnectorObjectTableOffset));
  131. }
  132. static struct graphics_object_id bios_parser_get_encoder_id(
  133. struct dc_bios *dcb,
  134. uint32_t i)
  135. {
  136. struct bios_parser *bp = BP_FROM_DCB(dcb);
  137. struct graphics_object_id object_id = dal_graphics_object_id_init(
  138. 0, ENUM_ID_UNKNOWN, OBJECT_TYPE_UNKNOWN);
  139. uint32_t encoder_table_offset = bp->object_info_tbl_offset
  140. + le16_to_cpu(bp->object_info_tbl.v1_1->usEncoderObjectTableOffset);
  141. ATOM_OBJECT_TABLE *tbl =
  142. GET_IMAGE(ATOM_OBJECT_TABLE, encoder_table_offset);
  143. if (tbl && tbl->ucNumberOfObjects > i) {
  144. const uint16_t id = le16_to_cpu(tbl->asObjects[i].usObjectID);
  145. object_id = object_id_from_bios_object_id(id);
  146. }
  147. return object_id;
  148. }
  149. static struct graphics_object_id bios_parser_get_connector_id(
  150. struct dc_bios *dcb,
  151. uint8_t i)
  152. {
  153. struct bios_parser *bp = BP_FROM_DCB(dcb);
  154. struct graphics_object_id object_id = dal_graphics_object_id_init(
  155. 0, ENUM_ID_UNKNOWN, OBJECT_TYPE_UNKNOWN);
  156. uint32_t connector_table_offset = bp->object_info_tbl_offset
  157. + le16_to_cpu(bp->object_info_tbl.v1_1->usConnectorObjectTableOffset);
  158. ATOM_OBJECT_TABLE *tbl =
  159. GET_IMAGE(ATOM_OBJECT_TABLE, connector_table_offset);
  160. if (tbl && tbl->ucNumberOfObjects > i) {
  161. const uint16_t id = le16_to_cpu(tbl->asObjects[i].usObjectID);
  162. object_id = object_id_from_bios_object_id(id);
  163. }
  164. return object_id;
  165. }
  166. static uint32_t bios_parser_get_dst_number(struct dc_bios *dcb,
  167. struct graphics_object_id id)
  168. {
  169. struct bios_parser *bp = BP_FROM_DCB(dcb);
  170. ATOM_OBJECT *object = get_bios_object(bp, id);
  171. return get_dst_number_from_object(bp, object);
  172. }
  173. static enum bp_result bios_parser_get_src_obj(struct dc_bios *dcb,
  174. struct graphics_object_id object_id, uint32_t index,
  175. struct graphics_object_id *src_object_id)
  176. {
  177. uint32_t number;
  178. uint16_t *id;
  179. ATOM_OBJECT *object;
  180. struct bios_parser *bp = BP_FROM_DCB(dcb);
  181. if (!src_object_id)
  182. return BP_RESULT_BADINPUT;
  183. object = get_bios_object(bp, object_id);
  184. if (!object) {
  185. BREAK_TO_DEBUGGER(); /* Invalid object id */
  186. return BP_RESULT_BADINPUT;
  187. }
  188. number = get_src_obj_list(bp, object, &id);
  189. if (number <= index)
  190. return BP_RESULT_BADINPUT;
  191. *src_object_id = object_id_from_bios_object_id(id[index]);
  192. return BP_RESULT_OK;
  193. }
  194. static enum bp_result bios_parser_get_dst_obj(struct dc_bios *dcb,
  195. struct graphics_object_id object_id, uint32_t index,
  196. struct graphics_object_id *dest_object_id)
  197. {
  198. uint32_t number;
  199. uint16_t *id = NULL;
  200. ATOM_OBJECT *object;
  201. struct bios_parser *bp = BP_FROM_DCB(dcb);
  202. if (!dest_object_id)
  203. return BP_RESULT_BADINPUT;
  204. object = get_bios_object(bp, object_id);
  205. number = get_dest_obj_list(bp, object, &id);
  206. if (number <= index || !id)
  207. return BP_RESULT_BADINPUT;
  208. *dest_object_id = object_id_from_bios_object_id(id[index]);
  209. return BP_RESULT_OK;
  210. }
  211. static enum bp_result bios_parser_get_i2c_info(struct dc_bios *dcb,
  212. struct graphics_object_id id,
  213. struct graphics_object_i2c_info *info)
  214. {
  215. uint32_t offset;
  216. ATOM_OBJECT *object;
  217. ATOM_COMMON_RECORD_HEADER *header;
  218. ATOM_I2C_RECORD *record;
  219. struct bios_parser *bp = BP_FROM_DCB(dcb);
  220. if (!info)
  221. return BP_RESULT_BADINPUT;
  222. object = get_bios_object(bp, id);
  223. if (!object)
  224. return BP_RESULT_BADINPUT;
  225. offset = le16_to_cpu(object->usRecordOffset)
  226. + bp->object_info_tbl_offset;
  227. for (;;) {
  228. header = GET_IMAGE(ATOM_COMMON_RECORD_HEADER, offset);
  229. if (!header)
  230. return BP_RESULT_BADBIOSTABLE;
  231. if (LAST_RECORD_TYPE == header->ucRecordType ||
  232. !header->ucRecordSize)
  233. break;
  234. if (ATOM_I2C_RECORD_TYPE == header->ucRecordType
  235. && sizeof(ATOM_I2C_RECORD) <= header->ucRecordSize) {
  236. /* get the I2C info */
  237. record = (ATOM_I2C_RECORD *) header;
  238. if (get_gpio_i2c_info(bp, record, info) == BP_RESULT_OK)
  239. return BP_RESULT_OK;
  240. }
  241. offset += header->ucRecordSize;
  242. }
  243. return BP_RESULT_NORECORD;
  244. }
  245. static enum bp_result get_voltage_ddc_info_v1(uint8_t *i2c_line,
  246. ATOM_COMMON_TABLE_HEADER *header,
  247. uint8_t *address)
  248. {
  249. enum bp_result result = BP_RESULT_NORECORD;
  250. ATOM_VOLTAGE_OBJECT_INFO *info =
  251. (ATOM_VOLTAGE_OBJECT_INFO *) address;
  252. uint8_t *voltage_current_object = (uint8_t *) &info->asVoltageObj[0];
  253. while ((address + le16_to_cpu(header->usStructureSize)) > voltage_current_object) {
  254. ATOM_VOLTAGE_OBJECT *object =
  255. (ATOM_VOLTAGE_OBJECT *) voltage_current_object;
  256. if ((object->ucVoltageType == SET_VOLTAGE_INIT_MODE) &&
  257. (object->ucVoltageType &
  258. VOLTAGE_CONTROLLED_BY_I2C_MASK)) {
  259. *i2c_line = object->asControl.ucVoltageControlI2cLine
  260. ^ 0x90;
  261. result = BP_RESULT_OK;
  262. break;
  263. }
  264. voltage_current_object += object->ucSize;
  265. }
  266. return result;
  267. }
  268. static enum bp_result get_voltage_ddc_info_v3(uint8_t *i2c_line,
  269. uint32_t index,
  270. ATOM_COMMON_TABLE_HEADER *header,
  271. uint8_t *address)
  272. {
  273. enum bp_result result = BP_RESULT_NORECORD;
  274. ATOM_VOLTAGE_OBJECT_INFO_V3_1 *info =
  275. (ATOM_VOLTAGE_OBJECT_INFO_V3_1 *) address;
  276. uint8_t *voltage_current_object =
  277. (uint8_t *) (&(info->asVoltageObj[0]));
  278. while ((address + le16_to_cpu(header->usStructureSize)) > voltage_current_object) {
  279. ATOM_I2C_VOLTAGE_OBJECT_V3 *object =
  280. (ATOM_I2C_VOLTAGE_OBJECT_V3 *) voltage_current_object;
  281. if (object->sHeader.ucVoltageMode ==
  282. ATOM_INIT_VOLTAGE_REGULATOR) {
  283. if (object->sHeader.ucVoltageType == index) {
  284. *i2c_line = object->ucVoltageControlI2cLine
  285. ^ 0x90;
  286. result = BP_RESULT_OK;
  287. break;
  288. }
  289. }
  290. voltage_current_object += le16_to_cpu(object->sHeader.usSize);
  291. }
  292. return result;
  293. }
  294. static enum bp_result bios_parser_get_thermal_ddc_info(
  295. struct dc_bios *dcb,
  296. uint32_t i2c_channel_id,
  297. struct graphics_object_i2c_info *info)
  298. {
  299. struct bios_parser *bp = BP_FROM_DCB(dcb);
  300. ATOM_I2C_ID_CONFIG_ACCESS *config;
  301. ATOM_I2C_RECORD record;
  302. if (!info)
  303. return BP_RESULT_BADINPUT;
  304. config = (ATOM_I2C_ID_CONFIG_ACCESS *) &i2c_channel_id;
  305. record.sucI2cId.bfHW_Capable = config->sbfAccess.bfHW_Capable;
  306. record.sucI2cId.bfI2C_LineMux = config->sbfAccess.bfI2C_LineMux;
  307. record.sucI2cId.bfHW_EngineID = config->sbfAccess.bfHW_EngineID;
  308. return get_gpio_i2c_info(bp, &record, info);
  309. }
  310. static enum bp_result bios_parser_get_voltage_ddc_info(struct dc_bios *dcb,
  311. uint32_t index,
  312. struct graphics_object_i2c_info *info)
  313. {
  314. uint8_t i2c_line = 0;
  315. enum bp_result result = BP_RESULT_NORECORD;
  316. uint8_t *voltage_info_address;
  317. ATOM_COMMON_TABLE_HEADER *header;
  318. struct atom_data_revision revision = {0};
  319. struct bios_parser *bp = BP_FROM_DCB(dcb);
  320. if (!DATA_TABLES(VoltageObjectInfo))
  321. return result;
  322. voltage_info_address = bios_get_image(&bp->base, DATA_TABLES(VoltageObjectInfo), sizeof(ATOM_COMMON_TABLE_HEADER));
  323. header = (ATOM_COMMON_TABLE_HEADER *) voltage_info_address;
  324. get_atom_data_table_revision(header, &revision);
  325. switch (revision.major) {
  326. case 1:
  327. case 2:
  328. result = get_voltage_ddc_info_v1(&i2c_line, header,
  329. voltage_info_address);
  330. break;
  331. case 3:
  332. if (revision.minor != 1)
  333. break;
  334. result = get_voltage_ddc_info_v3(&i2c_line, index, header,
  335. voltage_info_address);
  336. break;
  337. }
  338. if (result == BP_RESULT_OK)
  339. result = bios_parser_get_thermal_ddc_info(dcb,
  340. i2c_line, info);
  341. return result;
  342. }
  343. /* TODO: temporary commented out to suppress 'defined but not used' warning */
  344. #if 0
  345. static enum bp_result bios_parser_get_ddc_info_for_i2c_line(
  346. struct bios_parser *bp,
  347. uint8_t i2c_line, struct graphics_object_i2c_info *info)
  348. {
  349. uint32_t offset;
  350. ATOM_OBJECT *object;
  351. ATOM_OBJECT_TABLE *table;
  352. uint32_t i;
  353. if (!info)
  354. return BP_RESULT_BADINPUT;
  355. offset = le16_to_cpu(bp->object_info_tbl.v1_1->usConnectorObjectTableOffset);
  356. offset += bp->object_info_tbl_offset;
  357. table = GET_IMAGE(ATOM_OBJECT_TABLE, offset);
  358. if (!table)
  359. return BP_RESULT_BADBIOSTABLE;
  360. for (i = 0; i < table->ucNumberOfObjects; i++) {
  361. object = &table->asObjects[i];
  362. if (!object) {
  363. BREAK_TO_DEBUGGER(); /* Invalid object id */
  364. return BP_RESULT_BADINPUT;
  365. }
  366. offset = le16_to_cpu(object->usRecordOffset)
  367. + bp->object_info_tbl_offset;
  368. for (;;) {
  369. ATOM_COMMON_RECORD_HEADER *header =
  370. GET_IMAGE(ATOM_COMMON_RECORD_HEADER, offset);
  371. if (!header)
  372. return BP_RESULT_BADBIOSTABLE;
  373. offset += header->ucRecordSize;
  374. if (LAST_RECORD_TYPE == header->ucRecordType ||
  375. !header->ucRecordSize)
  376. break;
  377. if (ATOM_I2C_RECORD_TYPE == header->ucRecordType
  378. && sizeof(ATOM_I2C_RECORD) <=
  379. header->ucRecordSize) {
  380. ATOM_I2C_RECORD *record =
  381. (ATOM_I2C_RECORD *) header;
  382. if (i2c_line != record->sucI2cId.bfI2C_LineMux)
  383. continue;
  384. /* get the I2C info */
  385. if (get_gpio_i2c_info(bp, record, info) ==
  386. BP_RESULT_OK)
  387. return BP_RESULT_OK;
  388. }
  389. }
  390. }
  391. return BP_RESULT_NORECORD;
  392. }
  393. #endif
  394. static enum bp_result bios_parser_get_hpd_info(struct dc_bios *dcb,
  395. struct graphics_object_id id,
  396. struct graphics_object_hpd_info *info)
  397. {
  398. struct bios_parser *bp = BP_FROM_DCB(dcb);
  399. ATOM_OBJECT *object;
  400. ATOM_HPD_INT_RECORD *record = NULL;
  401. if (!info)
  402. return BP_RESULT_BADINPUT;
  403. object = get_bios_object(bp, id);
  404. if (!object)
  405. return BP_RESULT_BADINPUT;
  406. record = get_hpd_record(bp, object);
  407. if (record != NULL) {
  408. info->hpd_int_gpio_uid = record->ucHPDIntGPIOID;
  409. info->hpd_active = record->ucPlugged_PinState;
  410. return BP_RESULT_OK;
  411. }
  412. return BP_RESULT_NORECORD;
  413. }
  414. static enum bp_result bios_parser_get_device_tag_record(
  415. struct bios_parser *bp,
  416. ATOM_OBJECT *object,
  417. ATOM_CONNECTOR_DEVICE_TAG_RECORD **record)
  418. {
  419. ATOM_COMMON_RECORD_HEADER *header;
  420. uint32_t offset;
  421. offset = le16_to_cpu(object->usRecordOffset)
  422. + bp->object_info_tbl_offset;
  423. for (;;) {
  424. header = GET_IMAGE(ATOM_COMMON_RECORD_HEADER, offset);
  425. if (!header)
  426. return BP_RESULT_BADBIOSTABLE;
  427. offset += header->ucRecordSize;
  428. if (LAST_RECORD_TYPE == header->ucRecordType ||
  429. !header->ucRecordSize)
  430. break;
  431. if (ATOM_CONNECTOR_DEVICE_TAG_RECORD_TYPE !=
  432. header->ucRecordType)
  433. continue;
  434. if (sizeof(ATOM_CONNECTOR_DEVICE_TAG) > header->ucRecordSize)
  435. continue;
  436. *record = (ATOM_CONNECTOR_DEVICE_TAG_RECORD *) header;
  437. return BP_RESULT_OK;
  438. }
  439. return BP_RESULT_NORECORD;
  440. }
  441. static enum bp_result bios_parser_get_device_tag(
  442. struct dc_bios *dcb,
  443. struct graphics_object_id connector_object_id,
  444. uint32_t device_tag_index,
  445. struct connector_device_tag_info *info)
  446. {
  447. struct bios_parser *bp = BP_FROM_DCB(dcb);
  448. ATOM_OBJECT *object;
  449. ATOM_CONNECTOR_DEVICE_TAG_RECORD *record = NULL;
  450. ATOM_CONNECTOR_DEVICE_TAG *device_tag;
  451. if (!info)
  452. return BP_RESULT_BADINPUT;
  453. /* getBiosObject will return MXM object */
  454. object = get_bios_object(bp, connector_object_id);
  455. if (!object) {
  456. BREAK_TO_DEBUGGER(); /* Invalid object id */
  457. return BP_RESULT_BADINPUT;
  458. }
  459. if (bios_parser_get_device_tag_record(bp, object, &record)
  460. != BP_RESULT_OK)
  461. return BP_RESULT_NORECORD;
  462. if (device_tag_index >= record->ucNumberOfDevice)
  463. return BP_RESULT_NORECORD;
  464. device_tag = &record->asDeviceTag[device_tag_index];
  465. info->acpi_device = le32_to_cpu(device_tag->ulACPIDeviceEnum);
  466. info->dev_id =
  467. device_type_from_device_id(le16_to_cpu(device_tag->usDeviceID));
  468. return BP_RESULT_OK;
  469. }
  470. static enum bp_result get_firmware_info_v1_4(
  471. struct bios_parser *bp,
  472. struct dc_firmware_info *info);
  473. static enum bp_result get_firmware_info_v2_1(
  474. struct bios_parser *bp,
  475. struct dc_firmware_info *info);
  476. static enum bp_result get_firmware_info_v2_2(
  477. struct bios_parser *bp,
  478. struct dc_firmware_info *info);
  479. static enum bp_result bios_parser_get_firmware_info(
  480. struct dc_bios *dcb,
  481. struct dc_firmware_info *info)
  482. {
  483. struct bios_parser *bp = BP_FROM_DCB(dcb);
  484. enum bp_result result = BP_RESULT_BADBIOSTABLE;
  485. ATOM_COMMON_TABLE_HEADER *header;
  486. struct atom_data_revision revision;
  487. if (info && DATA_TABLES(FirmwareInfo)) {
  488. header = GET_IMAGE(ATOM_COMMON_TABLE_HEADER,
  489. DATA_TABLES(FirmwareInfo));
  490. get_atom_data_table_revision(header, &revision);
  491. switch (revision.major) {
  492. case 1:
  493. switch (revision.minor) {
  494. case 4:
  495. result = get_firmware_info_v1_4(bp, info);
  496. break;
  497. default:
  498. break;
  499. }
  500. break;
  501. case 2:
  502. switch (revision.minor) {
  503. case 1:
  504. result = get_firmware_info_v2_1(bp, info);
  505. break;
  506. case 2:
  507. result = get_firmware_info_v2_2(bp, info);
  508. break;
  509. default:
  510. break;
  511. }
  512. break;
  513. default:
  514. break;
  515. }
  516. }
  517. return result;
  518. }
  519. static enum bp_result get_firmware_info_v1_4(
  520. struct bios_parser *bp,
  521. struct dc_firmware_info *info)
  522. {
  523. ATOM_FIRMWARE_INFO_V1_4 *firmware_info =
  524. GET_IMAGE(ATOM_FIRMWARE_INFO_V1_4,
  525. DATA_TABLES(FirmwareInfo));
  526. if (!info)
  527. return BP_RESULT_BADINPUT;
  528. if (!firmware_info)
  529. return BP_RESULT_BADBIOSTABLE;
  530. memset(info, 0, sizeof(*info));
  531. /* Pixel clock pll information. We need to convert from 10KHz units into
  532. * KHz units */
  533. info->pll_info.crystal_frequency =
  534. le16_to_cpu(firmware_info->usReferenceClock) * 10;
  535. info->pll_info.min_input_pxl_clk_pll_frequency =
  536. le16_to_cpu(firmware_info->usMinPixelClockPLL_Input) * 10;
  537. info->pll_info.max_input_pxl_clk_pll_frequency =
  538. le16_to_cpu(firmware_info->usMaxPixelClockPLL_Input) * 10;
  539. info->pll_info.min_output_pxl_clk_pll_frequency =
  540. le32_to_cpu(firmware_info->ulMinPixelClockPLL_Output) * 10;
  541. info->pll_info.max_output_pxl_clk_pll_frequency =
  542. le32_to_cpu(firmware_info->ulMaxPixelClockPLL_Output) * 10;
  543. if (firmware_info->usFirmwareCapability.sbfAccess.MemoryClockSS_Support)
  544. /* Since there is no information on the SS, report conservative
  545. * value 3% for bandwidth calculation */
  546. /* unit of 0.01% */
  547. info->feature.memory_clk_ss_percentage = THREE_PERCENT_OF_10000;
  548. if (firmware_info->usFirmwareCapability.sbfAccess.EngineClockSS_Support)
  549. /* Since there is no information on the SS,report conservative
  550. * value 3% for bandwidth calculation */
  551. /* unit of 0.01% */
  552. info->feature.engine_clk_ss_percentage = THREE_PERCENT_OF_10000;
  553. return BP_RESULT_OK;
  554. }
  555. static enum bp_result get_ss_info_v3_1(
  556. struct bios_parser *bp,
  557. uint32_t id,
  558. uint32_t index,
  559. struct spread_spectrum_info *ss_info);
  560. static enum bp_result get_firmware_info_v2_1(
  561. struct bios_parser *bp,
  562. struct dc_firmware_info *info)
  563. {
  564. ATOM_FIRMWARE_INFO_V2_1 *firmwareInfo =
  565. GET_IMAGE(ATOM_FIRMWARE_INFO_V2_1, DATA_TABLES(FirmwareInfo));
  566. struct spread_spectrum_info internalSS;
  567. uint32_t index;
  568. if (!info)
  569. return BP_RESULT_BADINPUT;
  570. if (!firmwareInfo)
  571. return BP_RESULT_BADBIOSTABLE;
  572. memset(info, 0, sizeof(*info));
  573. /* Pixel clock pll information. We need to convert from 10KHz units into
  574. * KHz units */
  575. info->pll_info.crystal_frequency =
  576. le16_to_cpu(firmwareInfo->usCoreReferenceClock) * 10;
  577. info->pll_info.min_input_pxl_clk_pll_frequency =
  578. le16_to_cpu(firmwareInfo->usMinPixelClockPLL_Input) * 10;
  579. info->pll_info.max_input_pxl_clk_pll_frequency =
  580. le16_to_cpu(firmwareInfo->usMaxPixelClockPLL_Input) * 10;
  581. info->pll_info.min_output_pxl_clk_pll_frequency =
  582. le32_to_cpu(firmwareInfo->ulMinPixelClockPLL_Output) * 10;
  583. info->pll_info.max_output_pxl_clk_pll_frequency =
  584. le32_to_cpu(firmwareInfo->ulMaxPixelClockPLL_Output) * 10;
  585. info->default_display_engine_pll_frequency =
  586. le32_to_cpu(firmwareInfo->ulDefaultDispEngineClkFreq) * 10;
  587. info->external_clock_source_frequency_for_dp =
  588. le16_to_cpu(firmwareInfo->usUniphyDPModeExtClkFreq) * 10;
  589. info->min_allowed_bl_level = firmwareInfo->ucMinAllowedBL_Level;
  590. /* There should be only one entry in the SS info table for Memory Clock
  591. */
  592. index = 0;
  593. if (firmwareInfo->usFirmwareCapability.sbfAccess.MemoryClockSS_Support)
  594. /* Since there is no information for external SS, report
  595. * conservative value 3% for bandwidth calculation */
  596. /* unit of 0.01% */
  597. info->feature.memory_clk_ss_percentage = THREE_PERCENT_OF_10000;
  598. else if (get_ss_info_v3_1(bp,
  599. ASIC_INTERNAL_MEMORY_SS, index, &internalSS) == BP_RESULT_OK) {
  600. if (internalSS.spread_spectrum_percentage) {
  601. info->feature.memory_clk_ss_percentage =
  602. internalSS.spread_spectrum_percentage;
  603. if (internalSS.type.CENTER_MODE) {
  604. /* if it is centermode, the exact SS Percentage
  605. * will be round up of half of the percentage
  606. * reported in the SS table */
  607. ++info->feature.memory_clk_ss_percentage;
  608. info->feature.memory_clk_ss_percentage /= 2;
  609. }
  610. }
  611. }
  612. /* There should be only one entry in the SS info table for Engine Clock
  613. */
  614. index = 1;
  615. if (firmwareInfo->usFirmwareCapability.sbfAccess.EngineClockSS_Support)
  616. /* Since there is no information for external SS, report
  617. * conservative value 3% for bandwidth calculation */
  618. /* unit of 0.01% */
  619. info->feature.engine_clk_ss_percentage = THREE_PERCENT_OF_10000;
  620. else if (get_ss_info_v3_1(bp,
  621. ASIC_INTERNAL_ENGINE_SS, index, &internalSS) == BP_RESULT_OK) {
  622. if (internalSS.spread_spectrum_percentage) {
  623. info->feature.engine_clk_ss_percentage =
  624. internalSS.spread_spectrum_percentage;
  625. if (internalSS.type.CENTER_MODE) {
  626. /* if it is centermode, the exact SS Percentage
  627. * will be round up of half of the percentage
  628. * reported in the SS table */
  629. ++info->feature.engine_clk_ss_percentage;
  630. info->feature.engine_clk_ss_percentage /= 2;
  631. }
  632. }
  633. }
  634. return BP_RESULT_OK;
  635. }
  636. static enum bp_result get_firmware_info_v2_2(
  637. struct bios_parser *bp,
  638. struct dc_firmware_info *info)
  639. {
  640. ATOM_FIRMWARE_INFO_V2_2 *firmware_info;
  641. struct spread_spectrum_info internal_ss;
  642. uint32_t index;
  643. if (!info)
  644. return BP_RESULT_BADINPUT;
  645. firmware_info = GET_IMAGE(ATOM_FIRMWARE_INFO_V2_2,
  646. DATA_TABLES(FirmwareInfo));
  647. if (!firmware_info)
  648. return BP_RESULT_BADBIOSTABLE;
  649. memset(info, 0, sizeof(*info));
  650. /* Pixel clock pll information. We need to convert from 10KHz units into
  651. * KHz units */
  652. info->pll_info.crystal_frequency =
  653. le16_to_cpu(firmware_info->usCoreReferenceClock) * 10;
  654. info->pll_info.min_input_pxl_clk_pll_frequency =
  655. le16_to_cpu(firmware_info->usMinPixelClockPLL_Input) * 10;
  656. info->pll_info.max_input_pxl_clk_pll_frequency =
  657. le16_to_cpu(firmware_info->usMaxPixelClockPLL_Input) * 10;
  658. info->pll_info.min_output_pxl_clk_pll_frequency =
  659. le32_to_cpu(firmware_info->ulMinPixelClockPLL_Output) * 10;
  660. info->pll_info.max_output_pxl_clk_pll_frequency =
  661. le32_to_cpu(firmware_info->ulMaxPixelClockPLL_Output) * 10;
  662. info->default_display_engine_pll_frequency =
  663. le32_to_cpu(firmware_info->ulDefaultDispEngineClkFreq) * 10;
  664. info->external_clock_source_frequency_for_dp =
  665. le16_to_cpu(firmware_info->usUniphyDPModeExtClkFreq) * 10;
  666. /* There should be only one entry in the SS info table for Memory Clock
  667. */
  668. index = 0;
  669. if (firmware_info->usFirmwareCapability.sbfAccess.MemoryClockSS_Support)
  670. /* Since there is no information for external SS, report
  671. * conservative value 3% for bandwidth calculation */
  672. /* unit of 0.01% */
  673. info->feature.memory_clk_ss_percentage = THREE_PERCENT_OF_10000;
  674. else if (get_ss_info_v3_1(bp,
  675. ASIC_INTERNAL_MEMORY_SS, index, &internal_ss) == BP_RESULT_OK) {
  676. if (internal_ss.spread_spectrum_percentage) {
  677. info->feature.memory_clk_ss_percentage =
  678. internal_ss.spread_spectrum_percentage;
  679. if (internal_ss.type.CENTER_MODE) {
  680. /* if it is centermode, the exact SS Percentage
  681. * will be round up of half of the percentage
  682. * reported in the SS table */
  683. ++info->feature.memory_clk_ss_percentage;
  684. info->feature.memory_clk_ss_percentage /= 2;
  685. }
  686. }
  687. }
  688. /* There should be only one entry in the SS info table for Engine Clock
  689. */
  690. index = 1;
  691. if (firmware_info->usFirmwareCapability.sbfAccess.EngineClockSS_Support)
  692. /* Since there is no information for external SS, report
  693. * conservative value 3% for bandwidth calculation */
  694. /* unit of 0.01% */
  695. info->feature.engine_clk_ss_percentage = THREE_PERCENT_OF_10000;
  696. else if (get_ss_info_v3_1(bp,
  697. ASIC_INTERNAL_ENGINE_SS, index, &internal_ss) == BP_RESULT_OK) {
  698. if (internal_ss.spread_spectrum_percentage) {
  699. info->feature.engine_clk_ss_percentage =
  700. internal_ss.spread_spectrum_percentage;
  701. if (internal_ss.type.CENTER_MODE) {
  702. /* if it is centermode, the exact SS Percentage
  703. * will be round up of half of the percentage
  704. * reported in the SS table */
  705. ++info->feature.engine_clk_ss_percentage;
  706. info->feature.engine_clk_ss_percentage /= 2;
  707. }
  708. }
  709. }
  710. /* Remote Display */
  711. info->remote_display_config = firmware_info->ucRemoteDisplayConfig;
  712. /* Is allowed minimum BL level */
  713. info->min_allowed_bl_level = firmware_info->ucMinAllowedBL_Level;
  714. /* Used starting from CI */
  715. info->smu_gpu_pll_output_freq =
  716. (uint32_t) (le32_to_cpu(firmware_info->ulGPUPLL_OutputFreq) * 10);
  717. return BP_RESULT_OK;
  718. }
  719. static enum bp_result get_ss_info_v3_1(
  720. struct bios_parser *bp,
  721. uint32_t id,
  722. uint32_t index,
  723. struct spread_spectrum_info *ss_info)
  724. {
  725. ATOM_ASIC_INTERNAL_SS_INFO_V3 *ss_table_header_include;
  726. ATOM_ASIC_SS_ASSIGNMENT_V3 *tbl;
  727. uint32_t table_size;
  728. uint32_t i;
  729. uint32_t table_index = 0;
  730. if (!ss_info)
  731. return BP_RESULT_BADINPUT;
  732. if (!DATA_TABLES(ASIC_InternalSS_Info))
  733. return BP_RESULT_UNSUPPORTED;
  734. ss_table_header_include = GET_IMAGE(ATOM_ASIC_INTERNAL_SS_INFO_V3,
  735. DATA_TABLES(ASIC_InternalSS_Info));
  736. table_size =
  737. (le16_to_cpu(ss_table_header_include->sHeader.usStructureSize)
  738. - sizeof(ATOM_COMMON_TABLE_HEADER))
  739. / sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
  740. tbl = (ATOM_ASIC_SS_ASSIGNMENT_V3 *)
  741. &ss_table_header_include->asSpreadSpectrum[0];
  742. memset(ss_info, 0, sizeof(struct spread_spectrum_info));
  743. for (i = 0; i < table_size; i++) {
  744. if (tbl[i].ucClockIndication != (uint8_t) id)
  745. continue;
  746. if (table_index != index) {
  747. table_index++;
  748. continue;
  749. }
  750. /* VBIOS introduced new defines for Version 3, same values as
  751. * before, so now use these new ones for Version 3.
  752. * Shouldn't affect field VBIOS's V3 as define values are still
  753. * same.
  754. * #define SS_MODE_V3_CENTRE_SPREAD_MASK 0x01
  755. * #define SS_MODE_V3_EXTERNAL_SS_MASK 0x02
  756. * Old VBIOS defines:
  757. * #define ATOM_SS_CENTRE_SPREAD_MODE_MASK 0x00000001
  758. * #define ATOM_EXTERNAL_SS_MASK 0x00000002
  759. */
  760. if (SS_MODE_V3_EXTERNAL_SS_MASK & tbl[i].ucSpreadSpectrumMode)
  761. ss_info->type.EXTERNAL = true;
  762. if (SS_MODE_V3_CENTRE_SPREAD_MASK & tbl[i].ucSpreadSpectrumMode)
  763. ss_info->type.CENTER_MODE = true;
  764. /* Older VBIOS (in field) always provides SS percentage in 0.01%
  765. * units set Divider to 100 */
  766. ss_info->spread_percentage_divider = 100;
  767. /* #define SS_MODE_V3_PERCENTAGE_DIV_BY_1000_MASK 0x10 */
  768. if (SS_MODE_V3_PERCENTAGE_DIV_BY_1000_MASK
  769. & tbl[i].ucSpreadSpectrumMode)
  770. ss_info->spread_percentage_divider = 1000;
  771. ss_info->type.STEP_AND_DELAY_INFO = false;
  772. /* convert [10KHz] into [KHz] */
  773. ss_info->target_clock_range =
  774. le32_to_cpu(tbl[i].ulTargetClockRange) * 10;
  775. ss_info->spread_spectrum_percentage =
  776. (uint32_t)le16_to_cpu(tbl[i].usSpreadSpectrumPercentage);
  777. ss_info->spread_spectrum_range =
  778. (uint32_t)(le16_to_cpu(tbl[i].usSpreadRateIn10Hz) * 10);
  779. return BP_RESULT_OK;
  780. }
  781. return BP_RESULT_NORECORD;
  782. }
  783. static enum bp_result bios_parser_transmitter_control(
  784. struct dc_bios *dcb,
  785. struct bp_transmitter_control *cntl)
  786. {
  787. struct bios_parser *bp = BP_FROM_DCB(dcb);
  788. if (!bp->cmd_tbl.transmitter_control)
  789. return BP_RESULT_FAILURE;
  790. return bp->cmd_tbl.transmitter_control(bp, cntl);
  791. }
  792. static enum bp_result bios_parser_encoder_control(
  793. struct dc_bios *dcb,
  794. struct bp_encoder_control *cntl)
  795. {
  796. struct bios_parser *bp = BP_FROM_DCB(dcb);
  797. if (!bp->cmd_tbl.dig_encoder_control)
  798. return BP_RESULT_FAILURE;
  799. return bp->cmd_tbl.dig_encoder_control(bp, cntl);
  800. }
  801. static enum bp_result bios_parser_adjust_pixel_clock(
  802. struct dc_bios *dcb,
  803. struct bp_adjust_pixel_clock_parameters *bp_params)
  804. {
  805. struct bios_parser *bp = BP_FROM_DCB(dcb);
  806. if (!bp->cmd_tbl.adjust_display_pll)
  807. return BP_RESULT_FAILURE;
  808. return bp->cmd_tbl.adjust_display_pll(bp, bp_params);
  809. }
  810. static enum bp_result bios_parser_set_pixel_clock(
  811. struct dc_bios *dcb,
  812. struct bp_pixel_clock_parameters *bp_params)
  813. {
  814. struct bios_parser *bp = BP_FROM_DCB(dcb);
  815. if (!bp->cmd_tbl.set_pixel_clock)
  816. return BP_RESULT_FAILURE;
  817. return bp->cmd_tbl.set_pixel_clock(bp, bp_params);
  818. }
  819. static enum bp_result bios_parser_set_dce_clock(
  820. struct dc_bios *dcb,
  821. struct bp_set_dce_clock_parameters *bp_params)
  822. {
  823. struct bios_parser *bp = BP_FROM_DCB(dcb);
  824. if (!bp->cmd_tbl.set_dce_clock)
  825. return BP_RESULT_FAILURE;
  826. return bp->cmd_tbl.set_dce_clock(bp, bp_params);
  827. }
  828. static enum bp_result bios_parser_enable_spread_spectrum_on_ppll(
  829. struct dc_bios *dcb,
  830. struct bp_spread_spectrum_parameters *bp_params,
  831. bool enable)
  832. {
  833. struct bios_parser *bp = BP_FROM_DCB(dcb);
  834. if (!bp->cmd_tbl.enable_spread_spectrum_on_ppll)
  835. return BP_RESULT_FAILURE;
  836. return bp->cmd_tbl.enable_spread_spectrum_on_ppll(
  837. bp, bp_params, enable);
  838. }
  839. static enum bp_result bios_parser_program_crtc_timing(
  840. struct dc_bios *dcb,
  841. struct bp_hw_crtc_timing_parameters *bp_params)
  842. {
  843. struct bios_parser *bp = BP_FROM_DCB(dcb);
  844. if (!bp->cmd_tbl.set_crtc_timing)
  845. return BP_RESULT_FAILURE;
  846. return bp->cmd_tbl.set_crtc_timing(bp, bp_params);
  847. }
  848. static enum bp_result bios_parser_program_display_engine_pll(
  849. struct dc_bios *dcb,
  850. struct bp_pixel_clock_parameters *bp_params)
  851. {
  852. struct bios_parser *bp = BP_FROM_DCB(dcb);
  853. if (!bp->cmd_tbl.program_clock)
  854. return BP_RESULT_FAILURE;
  855. return bp->cmd_tbl.program_clock(bp, bp_params);
  856. }
  857. static enum bp_result bios_parser_enable_crtc(
  858. struct dc_bios *dcb,
  859. enum controller_id id,
  860. bool enable)
  861. {
  862. struct bios_parser *bp = BP_FROM_DCB(dcb);
  863. if (!bp->cmd_tbl.enable_crtc)
  864. return BP_RESULT_FAILURE;
  865. return bp->cmd_tbl.enable_crtc(bp, id, enable);
  866. }
  867. static enum bp_result bios_parser_crtc_source_select(
  868. struct dc_bios *dcb,
  869. struct bp_crtc_source_select *bp_params)
  870. {
  871. struct bios_parser *bp = BP_FROM_DCB(dcb);
  872. if (!bp->cmd_tbl.select_crtc_source)
  873. return BP_RESULT_FAILURE;
  874. return bp->cmd_tbl.select_crtc_source(bp, bp_params);
  875. }
  876. static enum bp_result bios_parser_enable_disp_power_gating(
  877. struct dc_bios *dcb,
  878. enum controller_id controller_id,
  879. enum bp_pipe_control_action action)
  880. {
  881. struct bios_parser *bp = BP_FROM_DCB(dcb);
  882. if (!bp->cmd_tbl.enable_disp_power_gating)
  883. return BP_RESULT_FAILURE;
  884. return bp->cmd_tbl.enable_disp_power_gating(bp, controller_id,
  885. action);
  886. }
  887. static bool bios_parser_is_device_id_supported(
  888. struct dc_bios *dcb,
  889. struct device_id id)
  890. {
  891. struct bios_parser *bp = BP_FROM_DCB(dcb);
  892. uint32_t mask = get_support_mask_for_device_id(id);
  893. return (le16_to_cpu(bp->object_info_tbl.v1_1->usDeviceSupport) & mask) != 0;
  894. }
  895. static enum bp_result bios_parser_crt_control(
  896. struct dc_bios *dcb,
  897. enum engine_id engine_id,
  898. bool enable,
  899. uint32_t pixel_clock)
  900. {
  901. struct bios_parser *bp = BP_FROM_DCB(dcb);
  902. uint8_t standard;
  903. if (!bp->cmd_tbl.dac1_encoder_control &&
  904. engine_id == ENGINE_ID_DACA)
  905. return BP_RESULT_FAILURE;
  906. if (!bp->cmd_tbl.dac2_encoder_control &&
  907. engine_id == ENGINE_ID_DACB)
  908. return BP_RESULT_FAILURE;
  909. /* validate params */
  910. switch (engine_id) {
  911. case ENGINE_ID_DACA:
  912. case ENGINE_ID_DACB:
  913. break;
  914. default:
  915. /* unsupported engine */
  916. return BP_RESULT_FAILURE;
  917. }
  918. standard = ATOM_DAC1_PS2; /* == ATOM_DAC2_PS2 */
  919. if (enable) {
  920. if (engine_id == ENGINE_ID_DACA) {
  921. bp->cmd_tbl.dac1_encoder_control(bp, enable,
  922. pixel_clock, standard);
  923. if (bp->cmd_tbl.dac1_output_control != NULL)
  924. bp->cmd_tbl.dac1_output_control(bp, enable);
  925. } else {
  926. bp->cmd_tbl.dac2_encoder_control(bp, enable,
  927. pixel_clock, standard);
  928. if (bp->cmd_tbl.dac2_output_control != NULL)
  929. bp->cmd_tbl.dac2_output_control(bp, enable);
  930. }
  931. } else {
  932. if (engine_id == ENGINE_ID_DACA) {
  933. if (bp->cmd_tbl.dac1_output_control != NULL)
  934. bp->cmd_tbl.dac1_output_control(bp, enable);
  935. bp->cmd_tbl.dac1_encoder_control(bp, enable,
  936. pixel_clock, standard);
  937. } else {
  938. if (bp->cmd_tbl.dac2_output_control != NULL)
  939. bp->cmd_tbl.dac2_output_control(bp, enable);
  940. bp->cmd_tbl.dac2_encoder_control(bp, enable,
  941. pixel_clock, standard);
  942. }
  943. }
  944. return BP_RESULT_OK;
  945. }
  946. static ATOM_HPD_INT_RECORD *get_hpd_record(struct bios_parser *bp,
  947. ATOM_OBJECT *object)
  948. {
  949. ATOM_COMMON_RECORD_HEADER *header;
  950. uint32_t offset;
  951. if (!object) {
  952. BREAK_TO_DEBUGGER(); /* Invalid object */
  953. return NULL;
  954. }
  955. offset = le16_to_cpu(object->usRecordOffset)
  956. + bp->object_info_tbl_offset;
  957. for (;;) {
  958. header = GET_IMAGE(ATOM_COMMON_RECORD_HEADER, offset);
  959. if (!header)
  960. return NULL;
  961. if (LAST_RECORD_TYPE == header->ucRecordType ||
  962. !header->ucRecordSize)
  963. break;
  964. if (ATOM_HPD_INT_RECORD_TYPE == header->ucRecordType
  965. && sizeof(ATOM_HPD_INT_RECORD) <= header->ucRecordSize)
  966. return (ATOM_HPD_INT_RECORD *) header;
  967. offset += header->ucRecordSize;
  968. }
  969. return NULL;
  970. }
  971. /**
  972. * Get I2C information of input object id
  973. *
  974. * search all records to find the ATOM_I2C_RECORD_TYPE record IR
  975. */
  976. static ATOM_I2C_RECORD *get_i2c_record(
  977. struct bios_parser *bp,
  978. ATOM_OBJECT *object)
  979. {
  980. uint32_t offset;
  981. ATOM_COMMON_RECORD_HEADER *record_header;
  982. if (!object) {
  983. BREAK_TO_DEBUGGER();
  984. /* Invalid object */
  985. return NULL;
  986. }
  987. offset = le16_to_cpu(object->usRecordOffset)
  988. + bp->object_info_tbl_offset;
  989. for (;;) {
  990. record_header = GET_IMAGE(ATOM_COMMON_RECORD_HEADER, offset);
  991. if (!record_header)
  992. return NULL;
  993. if (LAST_RECORD_TYPE == record_header->ucRecordType ||
  994. 0 == record_header->ucRecordSize)
  995. break;
  996. if (ATOM_I2C_RECORD_TYPE == record_header->ucRecordType &&
  997. sizeof(ATOM_I2C_RECORD) <=
  998. record_header->ucRecordSize) {
  999. return (ATOM_I2C_RECORD *)record_header;
  1000. }
  1001. offset += record_header->ucRecordSize;
  1002. }
  1003. return NULL;
  1004. }
  1005. static enum bp_result get_ss_info_from_ss_info_table(
  1006. struct bios_parser *bp,
  1007. uint32_t id,
  1008. struct spread_spectrum_info *ss_info);
  1009. static enum bp_result get_ss_info_from_tbl(
  1010. struct bios_parser *bp,
  1011. uint32_t id,
  1012. struct spread_spectrum_info *ss_info);
  1013. /**
  1014. * bios_parser_get_spread_spectrum_info
  1015. * Get spread spectrum information from the ASIC_InternalSS_Info(ver 2.1 or
  1016. * ver 3.1) or SS_Info table from the VBIOS. Currently ASIC_InternalSS_Info
  1017. * ver 2.1 can co-exist with SS_Info table. Expect ASIC_InternalSS_Info ver 3.1,
  1018. * there is only one entry for each signal /ss id. However, there is
  1019. * no planning of supporting multiple spread Sprectum entry for EverGreen
  1020. * @param [in] this
  1021. * @param [in] signal, ASSignalType to be converted to info index
  1022. * @param [in] index, number of entries that match the converted info index
  1023. * @param [out] ss_info, sprectrum information structure,
  1024. * @return Bios parser result code
  1025. */
  1026. static enum bp_result bios_parser_get_spread_spectrum_info(
  1027. struct dc_bios *dcb,
  1028. enum as_signal_type signal,
  1029. uint32_t index,
  1030. struct spread_spectrum_info *ss_info)
  1031. {
  1032. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1033. enum bp_result result = BP_RESULT_UNSUPPORTED;
  1034. uint32_t clk_id_ss = 0;
  1035. ATOM_COMMON_TABLE_HEADER *header;
  1036. struct atom_data_revision tbl_revision;
  1037. if (!ss_info) /* check for bad input */
  1038. return BP_RESULT_BADINPUT;
  1039. /* signal translation */
  1040. clk_id_ss = signal_to_ss_id(signal);
  1041. if (!DATA_TABLES(ASIC_InternalSS_Info))
  1042. if (!index)
  1043. return get_ss_info_from_ss_info_table(bp, clk_id_ss,
  1044. ss_info);
  1045. header = GET_IMAGE(ATOM_COMMON_TABLE_HEADER,
  1046. DATA_TABLES(ASIC_InternalSS_Info));
  1047. get_atom_data_table_revision(header, &tbl_revision);
  1048. switch (tbl_revision.major) {
  1049. case 2:
  1050. switch (tbl_revision.minor) {
  1051. case 1:
  1052. /* there can not be more then one entry for Internal
  1053. * SS Info table version 2.1 */
  1054. if (!index)
  1055. return get_ss_info_from_tbl(bp, clk_id_ss,
  1056. ss_info);
  1057. break;
  1058. default:
  1059. break;
  1060. }
  1061. break;
  1062. case 3:
  1063. switch (tbl_revision.minor) {
  1064. case 1:
  1065. return get_ss_info_v3_1(bp, clk_id_ss, index, ss_info);
  1066. default:
  1067. break;
  1068. }
  1069. break;
  1070. default:
  1071. break;
  1072. }
  1073. /* there can not be more then one entry for SS Info table */
  1074. return result;
  1075. }
  1076. static enum bp_result get_ss_info_from_internal_ss_info_tbl_V2_1(
  1077. struct bios_parser *bp,
  1078. uint32_t id,
  1079. struct spread_spectrum_info *info);
  1080. /**
  1081. * get_ss_info_from_table
  1082. * Get spread sprectrum information from the ASIC_InternalSS_Info Ver 2.1 or
  1083. * SS_Info table from the VBIOS
  1084. * There can not be more than 1 entry for ASIC_InternalSS_Info Ver 2.1 or
  1085. * SS_Info.
  1086. *
  1087. * @param this
  1088. * @param id, spread sprectrum info index
  1089. * @param pSSinfo, sprectrum information structure,
  1090. * @return Bios parser result code
  1091. */
  1092. static enum bp_result get_ss_info_from_tbl(
  1093. struct bios_parser *bp,
  1094. uint32_t id,
  1095. struct spread_spectrum_info *ss_info)
  1096. {
  1097. if (!ss_info) /* check for bad input, if ss_info is not NULL */
  1098. return BP_RESULT_BADINPUT;
  1099. /* for SS_Info table only support DP and LVDS */
  1100. if (id == ASIC_INTERNAL_SS_ON_DP || id == ASIC_INTERNAL_SS_ON_LVDS)
  1101. return get_ss_info_from_ss_info_table(bp, id, ss_info);
  1102. else
  1103. return get_ss_info_from_internal_ss_info_tbl_V2_1(bp, id,
  1104. ss_info);
  1105. }
  1106. /**
  1107. * get_ss_info_from_internal_ss_info_tbl_V2_1
  1108. * Get spread sprectrum information from the ASIC_InternalSS_Info table Ver 2.1
  1109. * from the VBIOS
  1110. * There will not be multiple entry for Ver 2.1
  1111. *
  1112. * @param id, spread sprectrum info index
  1113. * @param pSSinfo, sprectrum information structure,
  1114. * @return Bios parser result code
  1115. */
  1116. static enum bp_result get_ss_info_from_internal_ss_info_tbl_V2_1(
  1117. struct bios_parser *bp,
  1118. uint32_t id,
  1119. struct spread_spectrum_info *info)
  1120. {
  1121. enum bp_result result = BP_RESULT_UNSUPPORTED;
  1122. ATOM_ASIC_INTERNAL_SS_INFO_V2 *header;
  1123. ATOM_ASIC_SS_ASSIGNMENT_V2 *tbl;
  1124. uint32_t tbl_size, i;
  1125. if (!DATA_TABLES(ASIC_InternalSS_Info))
  1126. return result;
  1127. header = GET_IMAGE(ATOM_ASIC_INTERNAL_SS_INFO_V2,
  1128. DATA_TABLES(ASIC_InternalSS_Info));
  1129. memset(info, 0, sizeof(struct spread_spectrum_info));
  1130. tbl_size = (le16_to_cpu(header->sHeader.usStructureSize)
  1131. - sizeof(ATOM_COMMON_TABLE_HEADER))
  1132. / sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
  1133. tbl = (ATOM_ASIC_SS_ASSIGNMENT_V2 *)
  1134. &(header->asSpreadSpectrum[0]);
  1135. for (i = 0; i < tbl_size; i++) {
  1136. result = BP_RESULT_NORECORD;
  1137. if (tbl[i].ucClockIndication != (uint8_t)id)
  1138. continue;
  1139. if (ATOM_EXTERNAL_SS_MASK
  1140. & tbl[i].ucSpreadSpectrumMode) {
  1141. info->type.EXTERNAL = true;
  1142. }
  1143. if (ATOM_SS_CENTRE_SPREAD_MODE_MASK
  1144. & tbl[i].ucSpreadSpectrumMode) {
  1145. info->type.CENTER_MODE = true;
  1146. }
  1147. info->type.STEP_AND_DELAY_INFO = false;
  1148. /* convert [10KHz] into [KHz] */
  1149. info->target_clock_range =
  1150. le32_to_cpu(tbl[i].ulTargetClockRange) * 10;
  1151. info->spread_spectrum_percentage =
  1152. (uint32_t)le16_to_cpu(tbl[i].usSpreadSpectrumPercentage);
  1153. info->spread_spectrum_range =
  1154. (uint32_t)(le16_to_cpu(tbl[i].usSpreadRateIn10Hz) * 10);
  1155. result = BP_RESULT_OK;
  1156. break;
  1157. }
  1158. return result;
  1159. }
  1160. /**
  1161. * get_ss_info_from_ss_info_table
  1162. * Get spread sprectrum information from the SS_Info table from the VBIOS
  1163. * if the pointer to info is NULL, indicate the caller what to know the number
  1164. * of entries that matches the id
  1165. * for, the SS_Info table, there should not be more than 1 entry match.
  1166. *
  1167. * @param [in] id, spread sprectrum id
  1168. * @param [out] pSSinfo, sprectrum information structure,
  1169. * @return Bios parser result code
  1170. */
  1171. static enum bp_result get_ss_info_from_ss_info_table(
  1172. struct bios_parser *bp,
  1173. uint32_t id,
  1174. struct spread_spectrum_info *ss_info)
  1175. {
  1176. enum bp_result result = BP_RESULT_UNSUPPORTED;
  1177. ATOM_SPREAD_SPECTRUM_INFO *tbl;
  1178. ATOM_COMMON_TABLE_HEADER *header;
  1179. uint32_t table_size;
  1180. uint32_t i;
  1181. uint32_t id_local = SS_ID_UNKNOWN;
  1182. struct atom_data_revision revision;
  1183. /* exist of the SS_Info table */
  1184. /* check for bad input, pSSinfo can not be NULL */
  1185. if (!DATA_TABLES(SS_Info) || !ss_info)
  1186. return result;
  1187. header = GET_IMAGE(ATOM_COMMON_TABLE_HEADER, DATA_TABLES(SS_Info));
  1188. get_atom_data_table_revision(header, &revision);
  1189. tbl = GET_IMAGE(ATOM_SPREAD_SPECTRUM_INFO, DATA_TABLES(SS_Info));
  1190. if (1 != revision.major || 2 > revision.minor)
  1191. return result;
  1192. /* have to convert from Internal_SS format to SS_Info format */
  1193. switch (id) {
  1194. case ASIC_INTERNAL_SS_ON_DP:
  1195. id_local = SS_ID_DP1;
  1196. break;
  1197. case ASIC_INTERNAL_SS_ON_LVDS:
  1198. {
  1199. struct embedded_panel_info panel_info;
  1200. if (bios_parser_get_embedded_panel_info(&bp->base, &panel_info)
  1201. == BP_RESULT_OK)
  1202. id_local = panel_info.ss_id;
  1203. break;
  1204. }
  1205. default:
  1206. break;
  1207. }
  1208. if (id_local == SS_ID_UNKNOWN)
  1209. return result;
  1210. table_size = (le16_to_cpu(tbl->sHeader.usStructureSize) -
  1211. sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1212. sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
  1213. for (i = 0; i < table_size; i++) {
  1214. if (id_local != (uint32_t)tbl->asSS_Info[i].ucSS_Id)
  1215. continue;
  1216. memset(ss_info, 0, sizeof(struct spread_spectrum_info));
  1217. if (ATOM_EXTERNAL_SS_MASK &
  1218. tbl->asSS_Info[i].ucSpreadSpectrumType)
  1219. ss_info->type.EXTERNAL = true;
  1220. if (ATOM_SS_CENTRE_SPREAD_MODE_MASK &
  1221. tbl->asSS_Info[i].ucSpreadSpectrumType)
  1222. ss_info->type.CENTER_MODE = true;
  1223. ss_info->type.STEP_AND_DELAY_INFO = true;
  1224. ss_info->spread_spectrum_percentage =
  1225. (uint32_t)le16_to_cpu(tbl->asSS_Info[i].usSpreadSpectrumPercentage);
  1226. ss_info->step_and_delay_info.step = tbl->asSS_Info[i].ucSS_Step;
  1227. ss_info->step_and_delay_info.delay =
  1228. tbl->asSS_Info[i].ucSS_Delay;
  1229. ss_info->step_and_delay_info.recommended_ref_div =
  1230. tbl->asSS_Info[i].ucRecommendedRef_Div;
  1231. ss_info->spread_spectrum_range =
  1232. (uint32_t)tbl->asSS_Info[i].ucSS_Range * 10000;
  1233. /* there will be only one entry for each display type in SS_info
  1234. * table */
  1235. result = BP_RESULT_OK;
  1236. break;
  1237. }
  1238. return result;
  1239. }
  1240. static enum bp_result get_embedded_panel_info_v1_2(
  1241. struct bios_parser *bp,
  1242. struct embedded_panel_info *info);
  1243. static enum bp_result get_embedded_panel_info_v1_3(
  1244. struct bios_parser *bp,
  1245. struct embedded_panel_info *info);
  1246. static enum bp_result bios_parser_get_embedded_panel_info(
  1247. struct dc_bios *dcb,
  1248. struct embedded_panel_info *info)
  1249. {
  1250. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1251. ATOM_COMMON_TABLE_HEADER *hdr;
  1252. if (!DATA_TABLES(LCD_Info))
  1253. return BP_RESULT_FAILURE;
  1254. hdr = GET_IMAGE(ATOM_COMMON_TABLE_HEADER, DATA_TABLES(LCD_Info));
  1255. if (!hdr)
  1256. return BP_RESULT_BADBIOSTABLE;
  1257. switch (hdr->ucTableFormatRevision) {
  1258. case 1:
  1259. switch (hdr->ucTableContentRevision) {
  1260. case 0:
  1261. case 1:
  1262. case 2:
  1263. return get_embedded_panel_info_v1_2(bp, info);
  1264. case 3:
  1265. return get_embedded_panel_info_v1_3(bp, info);
  1266. default:
  1267. break;
  1268. }
  1269. default:
  1270. break;
  1271. }
  1272. return BP_RESULT_FAILURE;
  1273. }
  1274. static enum bp_result get_embedded_panel_info_v1_2(
  1275. struct bios_parser *bp,
  1276. struct embedded_panel_info *info)
  1277. {
  1278. ATOM_LVDS_INFO_V12 *lvds;
  1279. if (!info)
  1280. return BP_RESULT_BADINPUT;
  1281. if (!DATA_TABLES(LVDS_Info))
  1282. return BP_RESULT_UNSUPPORTED;
  1283. lvds =
  1284. GET_IMAGE(ATOM_LVDS_INFO_V12, DATA_TABLES(LVDS_Info));
  1285. if (!lvds)
  1286. return BP_RESULT_BADBIOSTABLE;
  1287. if (1 != lvds->sHeader.ucTableFormatRevision
  1288. || 2 > lvds->sHeader.ucTableContentRevision)
  1289. return BP_RESULT_UNSUPPORTED;
  1290. memset(info, 0, sizeof(struct embedded_panel_info));
  1291. /* We need to convert from 10KHz units into KHz units*/
  1292. info->lcd_timing.pixel_clk =
  1293. le16_to_cpu(lvds->sLCDTiming.usPixClk) * 10;
  1294. /* usHActive does not include borders, according to VBIOS team*/
  1295. info->lcd_timing.horizontal_addressable =
  1296. le16_to_cpu(lvds->sLCDTiming.usHActive);
  1297. /* usHBlanking_Time includes borders, so we should really be subtracting
  1298. * borders duing this translation, but LVDS generally*/
  1299. /* doesn't have borders, so we should be okay leaving this as is for
  1300. * now. May need to revisit if we ever have LVDS with borders*/
  1301. info->lcd_timing.horizontal_blanking_time =
  1302. le16_to_cpu(lvds->sLCDTiming.usHBlanking_Time);
  1303. /* usVActive does not include borders, according to VBIOS team*/
  1304. info->lcd_timing.vertical_addressable =
  1305. le16_to_cpu(lvds->sLCDTiming.usVActive);
  1306. /* usVBlanking_Time includes borders, so we should really be subtracting
  1307. * borders duing this translation, but LVDS generally*/
  1308. /* doesn't have borders, so we should be okay leaving this as is for
  1309. * now. May need to revisit if we ever have LVDS with borders*/
  1310. info->lcd_timing.vertical_blanking_time =
  1311. le16_to_cpu(lvds->sLCDTiming.usVBlanking_Time);
  1312. info->lcd_timing.horizontal_sync_offset =
  1313. le16_to_cpu(lvds->sLCDTiming.usHSyncOffset);
  1314. info->lcd_timing.horizontal_sync_width =
  1315. le16_to_cpu(lvds->sLCDTiming.usHSyncWidth);
  1316. info->lcd_timing.vertical_sync_offset =
  1317. le16_to_cpu(lvds->sLCDTiming.usVSyncOffset);
  1318. info->lcd_timing.vertical_sync_width =
  1319. le16_to_cpu(lvds->sLCDTiming.usVSyncWidth);
  1320. info->lcd_timing.horizontal_border = lvds->sLCDTiming.ucHBorder;
  1321. info->lcd_timing.vertical_border = lvds->sLCDTiming.ucVBorder;
  1322. info->lcd_timing.misc_info.HORIZONTAL_CUT_OFF =
  1323. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.HorizontalCutOff;
  1324. info->lcd_timing.misc_info.H_SYNC_POLARITY =
  1325. ~(uint32_t)
  1326. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.HSyncPolarity;
  1327. info->lcd_timing.misc_info.V_SYNC_POLARITY =
  1328. ~(uint32_t)
  1329. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.VSyncPolarity;
  1330. info->lcd_timing.misc_info.VERTICAL_CUT_OFF =
  1331. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.VerticalCutOff;
  1332. info->lcd_timing.misc_info.H_REPLICATION_BY2 =
  1333. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.H_ReplicationBy2;
  1334. info->lcd_timing.misc_info.V_REPLICATION_BY2 =
  1335. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.V_ReplicationBy2;
  1336. info->lcd_timing.misc_info.COMPOSITE_SYNC =
  1337. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.CompositeSync;
  1338. info->lcd_timing.misc_info.INTERLACE =
  1339. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.Interlace;
  1340. info->lcd_timing.misc_info.DOUBLE_CLOCK =
  1341. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.DoubleClock;
  1342. info->ss_id = lvds->ucSS_Id;
  1343. {
  1344. uint8_t rr = le16_to_cpu(lvds->usSupportedRefreshRate);
  1345. /* Get minimum supported refresh rate*/
  1346. if (SUPPORTED_LCD_REFRESHRATE_30Hz & rr)
  1347. info->supported_rr.REFRESH_RATE_30HZ = 1;
  1348. else if (SUPPORTED_LCD_REFRESHRATE_40Hz & rr)
  1349. info->supported_rr.REFRESH_RATE_40HZ = 1;
  1350. else if (SUPPORTED_LCD_REFRESHRATE_48Hz & rr)
  1351. info->supported_rr.REFRESH_RATE_48HZ = 1;
  1352. else if (SUPPORTED_LCD_REFRESHRATE_50Hz & rr)
  1353. info->supported_rr.REFRESH_RATE_50HZ = 1;
  1354. else if (SUPPORTED_LCD_REFRESHRATE_60Hz & rr)
  1355. info->supported_rr.REFRESH_RATE_60HZ = 1;
  1356. }
  1357. /*Drr panel support can be reported by VBIOS*/
  1358. if (LCDPANEL_CAP_DRR_SUPPORTED
  1359. & lvds->ucLCDPanel_SpecialHandlingCap)
  1360. info->drr_enabled = 1;
  1361. if (ATOM_PANEL_MISC_DUAL & lvds->ucLVDS_Misc)
  1362. info->lcd_timing.misc_info.DOUBLE_CLOCK = true;
  1363. if (ATOM_PANEL_MISC_888RGB & lvds->ucLVDS_Misc)
  1364. info->lcd_timing.misc_info.RGB888 = true;
  1365. info->lcd_timing.misc_info.GREY_LEVEL =
  1366. (uint32_t) (ATOM_PANEL_MISC_GREY_LEVEL &
  1367. lvds->ucLVDS_Misc) >> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT;
  1368. if (ATOM_PANEL_MISC_SPATIAL & lvds->ucLVDS_Misc)
  1369. info->lcd_timing.misc_info.SPATIAL = true;
  1370. if (ATOM_PANEL_MISC_TEMPORAL & lvds->ucLVDS_Misc)
  1371. info->lcd_timing.misc_info.TEMPORAL = true;
  1372. if (ATOM_PANEL_MISC_API_ENABLED & lvds->ucLVDS_Misc)
  1373. info->lcd_timing.misc_info.API_ENABLED = true;
  1374. return BP_RESULT_OK;
  1375. }
  1376. static enum bp_result get_embedded_panel_info_v1_3(
  1377. struct bios_parser *bp,
  1378. struct embedded_panel_info *info)
  1379. {
  1380. ATOM_LCD_INFO_V13 *lvds;
  1381. if (!info)
  1382. return BP_RESULT_BADINPUT;
  1383. if (!DATA_TABLES(LCD_Info))
  1384. return BP_RESULT_UNSUPPORTED;
  1385. lvds = GET_IMAGE(ATOM_LCD_INFO_V13, DATA_TABLES(LCD_Info));
  1386. if (!lvds)
  1387. return BP_RESULT_BADBIOSTABLE;
  1388. if (!((1 == lvds->sHeader.ucTableFormatRevision)
  1389. && (3 <= lvds->sHeader.ucTableContentRevision)))
  1390. return BP_RESULT_UNSUPPORTED;
  1391. memset(info, 0, sizeof(struct embedded_panel_info));
  1392. /* We need to convert from 10KHz units into KHz units */
  1393. info->lcd_timing.pixel_clk =
  1394. le16_to_cpu(lvds->sLCDTiming.usPixClk) * 10;
  1395. /* usHActive does not include borders, according to VBIOS team */
  1396. info->lcd_timing.horizontal_addressable =
  1397. le16_to_cpu(lvds->sLCDTiming.usHActive);
  1398. /* usHBlanking_Time includes borders, so we should really be subtracting
  1399. * borders duing this translation, but LVDS generally*/
  1400. /* doesn't have borders, so we should be okay leaving this as is for
  1401. * now. May need to revisit if we ever have LVDS with borders*/
  1402. info->lcd_timing.horizontal_blanking_time =
  1403. le16_to_cpu(lvds->sLCDTiming.usHBlanking_Time);
  1404. /* usVActive does not include borders, according to VBIOS team*/
  1405. info->lcd_timing.vertical_addressable =
  1406. le16_to_cpu(lvds->sLCDTiming.usVActive);
  1407. /* usVBlanking_Time includes borders, so we should really be subtracting
  1408. * borders duing this translation, but LVDS generally*/
  1409. /* doesn't have borders, so we should be okay leaving this as is for
  1410. * now. May need to revisit if we ever have LVDS with borders*/
  1411. info->lcd_timing.vertical_blanking_time =
  1412. le16_to_cpu(lvds->sLCDTiming.usVBlanking_Time);
  1413. info->lcd_timing.horizontal_sync_offset =
  1414. le16_to_cpu(lvds->sLCDTiming.usHSyncOffset);
  1415. info->lcd_timing.horizontal_sync_width =
  1416. le16_to_cpu(lvds->sLCDTiming.usHSyncWidth);
  1417. info->lcd_timing.vertical_sync_offset =
  1418. le16_to_cpu(lvds->sLCDTiming.usVSyncOffset);
  1419. info->lcd_timing.vertical_sync_width =
  1420. le16_to_cpu(lvds->sLCDTiming.usVSyncWidth);
  1421. info->lcd_timing.horizontal_border = lvds->sLCDTiming.ucHBorder;
  1422. info->lcd_timing.vertical_border = lvds->sLCDTiming.ucVBorder;
  1423. info->lcd_timing.misc_info.HORIZONTAL_CUT_OFF =
  1424. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.HorizontalCutOff;
  1425. info->lcd_timing.misc_info.H_SYNC_POLARITY =
  1426. ~(uint32_t)
  1427. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.HSyncPolarity;
  1428. info->lcd_timing.misc_info.V_SYNC_POLARITY =
  1429. ~(uint32_t)
  1430. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.VSyncPolarity;
  1431. info->lcd_timing.misc_info.VERTICAL_CUT_OFF =
  1432. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.VerticalCutOff;
  1433. info->lcd_timing.misc_info.H_REPLICATION_BY2 =
  1434. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.H_ReplicationBy2;
  1435. info->lcd_timing.misc_info.V_REPLICATION_BY2 =
  1436. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.V_ReplicationBy2;
  1437. info->lcd_timing.misc_info.COMPOSITE_SYNC =
  1438. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.CompositeSync;
  1439. info->lcd_timing.misc_info.INTERLACE =
  1440. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.Interlace;
  1441. info->lcd_timing.misc_info.DOUBLE_CLOCK =
  1442. lvds->sLCDTiming.susModeMiscInfo.sbfAccess.DoubleClock;
  1443. info->ss_id = lvds->ucSS_Id;
  1444. /* Drr panel support can be reported by VBIOS*/
  1445. if (LCDPANEL_CAP_V13_DRR_SUPPORTED
  1446. & lvds->ucLCDPanel_SpecialHandlingCap)
  1447. info->drr_enabled = 1;
  1448. /* Get supported refresh rate*/
  1449. if (info->drr_enabled == 1) {
  1450. uint8_t min_rr =
  1451. lvds->sRefreshRateSupport.ucMinRefreshRateForDRR;
  1452. uint8_t rr = lvds->sRefreshRateSupport.ucSupportedRefreshRate;
  1453. if (min_rr != 0) {
  1454. if (SUPPORTED_LCD_REFRESHRATE_30Hz & min_rr)
  1455. info->supported_rr.REFRESH_RATE_30HZ = 1;
  1456. else if (SUPPORTED_LCD_REFRESHRATE_40Hz & min_rr)
  1457. info->supported_rr.REFRESH_RATE_40HZ = 1;
  1458. else if (SUPPORTED_LCD_REFRESHRATE_48Hz & min_rr)
  1459. info->supported_rr.REFRESH_RATE_48HZ = 1;
  1460. else if (SUPPORTED_LCD_REFRESHRATE_50Hz & min_rr)
  1461. info->supported_rr.REFRESH_RATE_50HZ = 1;
  1462. else if (SUPPORTED_LCD_REFRESHRATE_60Hz & min_rr)
  1463. info->supported_rr.REFRESH_RATE_60HZ = 1;
  1464. } else {
  1465. if (SUPPORTED_LCD_REFRESHRATE_30Hz & rr)
  1466. info->supported_rr.REFRESH_RATE_30HZ = 1;
  1467. else if (SUPPORTED_LCD_REFRESHRATE_40Hz & rr)
  1468. info->supported_rr.REFRESH_RATE_40HZ = 1;
  1469. else if (SUPPORTED_LCD_REFRESHRATE_48Hz & rr)
  1470. info->supported_rr.REFRESH_RATE_48HZ = 1;
  1471. else if (SUPPORTED_LCD_REFRESHRATE_50Hz & rr)
  1472. info->supported_rr.REFRESH_RATE_50HZ = 1;
  1473. else if (SUPPORTED_LCD_REFRESHRATE_60Hz & rr)
  1474. info->supported_rr.REFRESH_RATE_60HZ = 1;
  1475. }
  1476. }
  1477. if (ATOM_PANEL_MISC_V13_DUAL & lvds->ucLCD_Misc)
  1478. info->lcd_timing.misc_info.DOUBLE_CLOCK = true;
  1479. if (ATOM_PANEL_MISC_V13_8BIT_PER_COLOR & lvds->ucLCD_Misc)
  1480. info->lcd_timing.misc_info.RGB888 = true;
  1481. info->lcd_timing.misc_info.GREY_LEVEL =
  1482. (uint32_t) (ATOM_PANEL_MISC_V13_GREY_LEVEL &
  1483. lvds->ucLCD_Misc) >> ATOM_PANEL_MISC_V13_GREY_LEVEL_SHIFT;
  1484. return BP_RESULT_OK;
  1485. }
  1486. /**
  1487. * bios_parser_get_encoder_cap_info
  1488. *
  1489. * @brief
  1490. * Get encoder capability information of input object id
  1491. *
  1492. * @param object_id, Object id
  1493. * @param object_id, encoder cap information structure
  1494. *
  1495. * @return Bios parser result code
  1496. *
  1497. */
  1498. static enum bp_result bios_parser_get_encoder_cap_info(
  1499. struct dc_bios *dcb,
  1500. struct graphics_object_id object_id,
  1501. struct bp_encoder_cap_info *info)
  1502. {
  1503. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1504. ATOM_OBJECT *object;
  1505. ATOM_ENCODER_CAP_RECORD_V2 *record = NULL;
  1506. if (!info)
  1507. return BP_RESULT_BADINPUT;
  1508. object = get_bios_object(bp, object_id);
  1509. if (!object)
  1510. return BP_RESULT_BADINPUT;
  1511. record = get_encoder_cap_record(bp, object);
  1512. if (!record)
  1513. return BP_RESULT_NORECORD;
  1514. info->DP_HBR2_EN = record->usHBR2En;
  1515. info->DP_HBR3_EN = record->usHBR3En;
  1516. info->HDMI_6GB_EN = record->usHDMI6GEn;
  1517. return BP_RESULT_OK;
  1518. }
  1519. /**
  1520. * get_encoder_cap_record
  1521. *
  1522. * @brief
  1523. * Get encoder cap record for the object
  1524. *
  1525. * @param object, ATOM object
  1526. *
  1527. * @return atom encoder cap record
  1528. *
  1529. * @note
  1530. * search all records to find the ATOM_ENCODER_CAP_RECORD_V2 record
  1531. */
  1532. static ATOM_ENCODER_CAP_RECORD_V2 *get_encoder_cap_record(
  1533. struct bios_parser *bp,
  1534. ATOM_OBJECT *object)
  1535. {
  1536. ATOM_COMMON_RECORD_HEADER *header;
  1537. uint32_t offset;
  1538. if (!object) {
  1539. BREAK_TO_DEBUGGER(); /* Invalid object */
  1540. return NULL;
  1541. }
  1542. offset = le16_to_cpu(object->usRecordOffset)
  1543. + bp->object_info_tbl_offset;
  1544. for (;;) {
  1545. header = GET_IMAGE(ATOM_COMMON_RECORD_HEADER, offset);
  1546. if (!header)
  1547. return NULL;
  1548. offset += header->ucRecordSize;
  1549. if (LAST_RECORD_TYPE == header->ucRecordType ||
  1550. !header->ucRecordSize)
  1551. break;
  1552. if (ATOM_ENCODER_CAP_RECORD_TYPE != header->ucRecordType)
  1553. continue;
  1554. if (sizeof(ATOM_ENCODER_CAP_RECORD_V2) <= header->ucRecordSize)
  1555. return (ATOM_ENCODER_CAP_RECORD_V2 *)header;
  1556. }
  1557. return NULL;
  1558. }
  1559. static uint32_t get_ss_entry_number(
  1560. struct bios_parser *bp,
  1561. uint32_t id);
  1562. static uint32_t get_ss_entry_number_from_internal_ss_info_tbl_v2_1(
  1563. struct bios_parser *bp,
  1564. uint32_t id);
  1565. static uint32_t get_ss_entry_number_from_internal_ss_info_tbl_V3_1(
  1566. struct bios_parser *bp,
  1567. uint32_t id);
  1568. static uint32_t get_ss_entry_number_from_ss_info_tbl(
  1569. struct bios_parser *bp,
  1570. uint32_t id);
  1571. /**
  1572. * BiosParserObject::GetNumberofSpreadSpectrumEntry
  1573. * Get Number of SpreadSpectrum Entry from the ASIC_InternalSS_Info table from
  1574. * the VBIOS that match the SSid (to be converted from signal)
  1575. *
  1576. * @param[in] signal, ASSignalType to be converted to SSid
  1577. * @return number of SS Entry that match the signal
  1578. */
  1579. static uint32_t bios_parser_get_ss_entry_number(
  1580. struct dc_bios *dcb,
  1581. enum as_signal_type signal)
  1582. {
  1583. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1584. uint32_t ss_id = 0;
  1585. ATOM_COMMON_TABLE_HEADER *header;
  1586. struct atom_data_revision revision;
  1587. ss_id = signal_to_ss_id(signal);
  1588. if (!DATA_TABLES(ASIC_InternalSS_Info))
  1589. return get_ss_entry_number_from_ss_info_tbl(bp, ss_id);
  1590. header = GET_IMAGE(ATOM_COMMON_TABLE_HEADER,
  1591. DATA_TABLES(ASIC_InternalSS_Info));
  1592. get_atom_data_table_revision(header, &revision);
  1593. switch (revision.major) {
  1594. case 2:
  1595. switch (revision.minor) {
  1596. case 1:
  1597. return get_ss_entry_number(bp, ss_id);
  1598. default:
  1599. break;
  1600. }
  1601. break;
  1602. case 3:
  1603. switch (revision.minor) {
  1604. case 1:
  1605. return
  1606. get_ss_entry_number_from_internal_ss_info_tbl_V3_1(
  1607. bp, ss_id);
  1608. default:
  1609. break;
  1610. }
  1611. break;
  1612. default:
  1613. break;
  1614. }
  1615. return 0;
  1616. }
  1617. /**
  1618. * get_ss_entry_number_from_ss_info_tbl
  1619. * Get Number of spread spectrum entry from the SS_Info table from the VBIOS.
  1620. *
  1621. * @note There can only be one entry for each id for SS_Info Table
  1622. *
  1623. * @param [in] id, spread spectrum id
  1624. * @return number of SS Entry that match the id
  1625. */
  1626. static uint32_t get_ss_entry_number_from_ss_info_tbl(
  1627. struct bios_parser *bp,
  1628. uint32_t id)
  1629. {
  1630. ATOM_SPREAD_SPECTRUM_INFO *tbl;
  1631. ATOM_COMMON_TABLE_HEADER *header;
  1632. uint32_t table_size;
  1633. uint32_t i;
  1634. uint32_t number = 0;
  1635. uint32_t id_local = SS_ID_UNKNOWN;
  1636. struct atom_data_revision revision;
  1637. /* SS_Info table exist */
  1638. if (!DATA_TABLES(SS_Info))
  1639. return number;
  1640. header = GET_IMAGE(ATOM_COMMON_TABLE_HEADER,
  1641. DATA_TABLES(SS_Info));
  1642. get_atom_data_table_revision(header, &revision);
  1643. tbl = GET_IMAGE(ATOM_SPREAD_SPECTRUM_INFO,
  1644. DATA_TABLES(SS_Info));
  1645. if (1 != revision.major || 2 > revision.minor)
  1646. return number;
  1647. /* have to convert from Internal_SS format to SS_Info format */
  1648. switch (id) {
  1649. case ASIC_INTERNAL_SS_ON_DP:
  1650. id_local = SS_ID_DP1;
  1651. break;
  1652. case ASIC_INTERNAL_SS_ON_LVDS: {
  1653. struct embedded_panel_info panel_info;
  1654. if (bios_parser_get_embedded_panel_info(&bp->base, &panel_info)
  1655. == BP_RESULT_OK)
  1656. id_local = panel_info.ss_id;
  1657. break;
  1658. }
  1659. default:
  1660. break;
  1661. }
  1662. if (id_local == SS_ID_UNKNOWN)
  1663. return number;
  1664. table_size = (le16_to_cpu(tbl->sHeader.usStructureSize) -
  1665. sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1666. sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
  1667. for (i = 0; i < table_size; i++)
  1668. if (id_local == (uint32_t)tbl->asSS_Info[i].ucSS_Id) {
  1669. number = 1;
  1670. break;
  1671. }
  1672. return number;
  1673. }
  1674. /**
  1675. * get_ss_entry_number
  1676. * Get spread sprectrum information from the ASIC_InternalSS_Info Ver 2.1 or
  1677. * SS_Info table from the VBIOS
  1678. * There can not be more than 1 entry for ASIC_InternalSS_Info Ver 2.1 or
  1679. * SS_Info.
  1680. *
  1681. * @param id, spread sprectrum info index
  1682. * @return Bios parser result code
  1683. */
  1684. static uint32_t get_ss_entry_number(struct bios_parser *bp, uint32_t id)
  1685. {
  1686. if (id == ASIC_INTERNAL_SS_ON_DP || id == ASIC_INTERNAL_SS_ON_LVDS)
  1687. return get_ss_entry_number_from_ss_info_tbl(bp, id);
  1688. return get_ss_entry_number_from_internal_ss_info_tbl_v2_1(bp, id);
  1689. }
  1690. /**
  1691. * get_ss_entry_number_from_internal_ss_info_tbl_v2_1
  1692. * Get NUmber of spread sprectrum entry from the ASIC_InternalSS_Info table
  1693. * Ver 2.1 from the VBIOS
  1694. * There will not be multiple entry for Ver 2.1
  1695. *
  1696. * @param id, spread sprectrum info index
  1697. * @return number of SS Entry that match the id
  1698. */
  1699. static uint32_t get_ss_entry_number_from_internal_ss_info_tbl_v2_1(
  1700. struct bios_parser *bp,
  1701. uint32_t id)
  1702. {
  1703. ATOM_ASIC_INTERNAL_SS_INFO_V2 *header_include;
  1704. ATOM_ASIC_SS_ASSIGNMENT_V2 *tbl;
  1705. uint32_t size;
  1706. uint32_t i;
  1707. if (!DATA_TABLES(ASIC_InternalSS_Info))
  1708. return 0;
  1709. header_include = GET_IMAGE(ATOM_ASIC_INTERNAL_SS_INFO_V2,
  1710. DATA_TABLES(ASIC_InternalSS_Info));
  1711. size = (le16_to_cpu(header_include->sHeader.usStructureSize)
  1712. - sizeof(ATOM_COMMON_TABLE_HEADER))
  1713. / sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
  1714. tbl = (ATOM_ASIC_SS_ASSIGNMENT_V2 *)
  1715. &header_include->asSpreadSpectrum[0];
  1716. for (i = 0; i < size; i++)
  1717. if (tbl[i].ucClockIndication == (uint8_t)id)
  1718. return 1;
  1719. return 0;
  1720. }
  1721. /**
  1722. * get_ss_entry_number_from_internal_ss_info_table_V3_1
  1723. * Get Number of SpreadSpectrum Entry from the ASIC_InternalSS_Info table of
  1724. * the VBIOS that matches id
  1725. *
  1726. * @param[in] id, spread sprectrum id
  1727. * @return number of SS Entry that match the id
  1728. */
  1729. static uint32_t get_ss_entry_number_from_internal_ss_info_tbl_V3_1(
  1730. struct bios_parser *bp,
  1731. uint32_t id)
  1732. {
  1733. uint32_t number = 0;
  1734. ATOM_ASIC_INTERNAL_SS_INFO_V3 *header_include;
  1735. ATOM_ASIC_SS_ASSIGNMENT_V3 *tbl;
  1736. uint32_t size;
  1737. uint32_t i;
  1738. if (!DATA_TABLES(ASIC_InternalSS_Info))
  1739. return number;
  1740. header_include = GET_IMAGE(ATOM_ASIC_INTERNAL_SS_INFO_V3,
  1741. DATA_TABLES(ASIC_InternalSS_Info));
  1742. size = (le16_to_cpu(header_include->sHeader.usStructureSize) -
  1743. sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1744. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
  1745. tbl = (ATOM_ASIC_SS_ASSIGNMENT_V3 *)
  1746. &header_include->asSpreadSpectrum[0];
  1747. for (i = 0; i < size; i++)
  1748. if (tbl[i].ucClockIndication == (uint8_t)id)
  1749. number++;
  1750. return number;
  1751. }
  1752. /**
  1753. * bios_parser_get_gpio_pin_info
  1754. * Get GpioPin information of input gpio id
  1755. *
  1756. * @param gpio_id, GPIO ID
  1757. * @param info, GpioPin information structure
  1758. * @return Bios parser result code
  1759. * @note
  1760. * to get the GPIO PIN INFO, we need:
  1761. * 1. get the GPIO_ID from other object table, see GetHPDInfo()
  1762. * 2. in DATA_TABLE.GPIO_Pin_LUT, search all records, to get the registerA
  1763. * offset/mask
  1764. */
  1765. static enum bp_result bios_parser_get_gpio_pin_info(
  1766. struct dc_bios *dcb,
  1767. uint32_t gpio_id,
  1768. struct gpio_pin_info *info)
  1769. {
  1770. struct bios_parser *bp = BP_FROM_DCB(dcb);
  1771. ATOM_GPIO_PIN_LUT *header;
  1772. uint32_t count = 0;
  1773. uint32_t i = 0;
  1774. if (!DATA_TABLES(GPIO_Pin_LUT))
  1775. return BP_RESULT_BADBIOSTABLE;
  1776. header = GET_IMAGE(ATOM_GPIO_PIN_LUT, DATA_TABLES(GPIO_Pin_LUT));
  1777. if (!header)
  1778. return BP_RESULT_BADBIOSTABLE;
  1779. if (sizeof(ATOM_COMMON_TABLE_HEADER) + sizeof(ATOM_GPIO_PIN_LUT)
  1780. > le16_to_cpu(header->sHeader.usStructureSize))
  1781. return BP_RESULT_BADBIOSTABLE;
  1782. if (1 != header->sHeader.ucTableContentRevision)
  1783. return BP_RESULT_UNSUPPORTED;
  1784. count = (le16_to_cpu(header->sHeader.usStructureSize)
  1785. - sizeof(ATOM_COMMON_TABLE_HEADER))
  1786. / sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
  1787. for (i = 0; i < count; ++i) {
  1788. if (header->asGPIO_Pin[i].ucGPIO_ID != gpio_id)
  1789. continue;
  1790. info->offset =
  1791. (uint32_t) le16_to_cpu(header->asGPIO_Pin[i].usGpioPin_AIndex);
  1792. info->offset_y = info->offset + 2;
  1793. info->offset_en = info->offset + 1;
  1794. info->offset_mask = info->offset - 1;
  1795. info->mask = (uint32_t) (1 <<
  1796. header->asGPIO_Pin[i].ucGpioPinBitShift);
  1797. info->mask_y = info->mask + 2;
  1798. info->mask_en = info->mask + 1;
  1799. info->mask_mask = info->mask - 1;
  1800. return BP_RESULT_OK;
  1801. }
  1802. return BP_RESULT_NORECORD;
  1803. }
  1804. static enum bp_result get_gpio_i2c_info(struct bios_parser *bp,
  1805. ATOM_I2C_RECORD *record,
  1806. struct graphics_object_i2c_info *info)
  1807. {
  1808. ATOM_GPIO_I2C_INFO *header;
  1809. uint32_t count = 0;
  1810. if (!info)
  1811. return BP_RESULT_BADINPUT;
  1812. /* get the GPIO_I2C info */
  1813. if (!DATA_TABLES(GPIO_I2C_Info))
  1814. return BP_RESULT_BADBIOSTABLE;
  1815. header = GET_IMAGE(ATOM_GPIO_I2C_INFO, DATA_TABLES(GPIO_I2C_Info));
  1816. if (!header)
  1817. return BP_RESULT_BADBIOSTABLE;
  1818. if (sizeof(ATOM_COMMON_TABLE_HEADER) + sizeof(ATOM_GPIO_I2C_ASSIGMENT)
  1819. > le16_to_cpu(header->sHeader.usStructureSize))
  1820. return BP_RESULT_BADBIOSTABLE;
  1821. if (1 != header->sHeader.ucTableContentRevision)
  1822. return BP_RESULT_UNSUPPORTED;
  1823. /* get data count */
  1824. count = (le16_to_cpu(header->sHeader.usStructureSize)
  1825. - sizeof(ATOM_COMMON_TABLE_HEADER))
  1826. / sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  1827. if (count < record->sucI2cId.bfI2C_LineMux)
  1828. return BP_RESULT_BADBIOSTABLE;
  1829. /* get the GPIO_I2C_INFO */
  1830. info->i2c_hw_assist = record->sucI2cId.bfHW_Capable;
  1831. info->i2c_line = record->sucI2cId.bfI2C_LineMux;
  1832. info->i2c_engine_id = record->sucI2cId.bfHW_EngineID;
  1833. info->i2c_slave_address = record->ucI2CAddr;
  1834. info->gpio_info.clk_mask_register_index =
  1835. le16_to_cpu(header->asGPIO_Info[info->i2c_line].usClkMaskRegisterIndex);
  1836. info->gpio_info.clk_en_register_index =
  1837. le16_to_cpu(header->asGPIO_Info[info->i2c_line].usClkEnRegisterIndex);
  1838. info->gpio_info.clk_y_register_index =
  1839. le16_to_cpu(header->asGPIO_Info[info->i2c_line].usClkY_RegisterIndex);
  1840. info->gpio_info.clk_a_register_index =
  1841. le16_to_cpu(header->asGPIO_Info[info->i2c_line].usClkA_RegisterIndex);
  1842. info->gpio_info.data_mask_register_index =
  1843. le16_to_cpu(header->asGPIO_Info[info->i2c_line].usDataMaskRegisterIndex);
  1844. info->gpio_info.data_en_register_index =
  1845. le16_to_cpu(header->asGPIO_Info[info->i2c_line].usDataEnRegisterIndex);
  1846. info->gpio_info.data_y_register_index =
  1847. le16_to_cpu(header->asGPIO_Info[info->i2c_line].usDataY_RegisterIndex);
  1848. info->gpio_info.data_a_register_index =
  1849. le16_to_cpu(header->asGPIO_Info[info->i2c_line].usDataA_RegisterIndex);
  1850. info->gpio_info.clk_mask_shift =
  1851. header->asGPIO_Info[info->i2c_line].ucClkMaskShift;
  1852. info->gpio_info.clk_en_shift =
  1853. header->asGPIO_Info[info->i2c_line].ucClkEnShift;
  1854. info->gpio_info.clk_y_shift =
  1855. header->asGPIO_Info[info->i2c_line].ucClkY_Shift;
  1856. info->gpio_info.clk_a_shift =
  1857. header->asGPIO_Info[info->i2c_line].ucClkA_Shift;
  1858. info->gpio_info.data_mask_shift =
  1859. header->asGPIO_Info[info->i2c_line].ucDataMaskShift;
  1860. info->gpio_info.data_en_shift =
  1861. header->asGPIO_Info[info->i2c_line].ucDataEnShift;
  1862. info->gpio_info.data_y_shift =
  1863. header->asGPIO_Info[info->i2c_line].ucDataY_Shift;
  1864. info->gpio_info.data_a_shift =
  1865. header->asGPIO_Info[info->i2c_line].ucDataA_Shift;
  1866. return BP_RESULT_OK;
  1867. }
  1868. static ATOM_OBJECT *get_bios_object(struct bios_parser *bp,
  1869. struct graphics_object_id id)
  1870. {
  1871. uint32_t offset;
  1872. ATOM_OBJECT_TABLE *tbl;
  1873. uint32_t i;
  1874. switch (id.type) {
  1875. case OBJECT_TYPE_ENCODER:
  1876. offset = le16_to_cpu(bp->object_info_tbl.v1_1->usEncoderObjectTableOffset);
  1877. break;
  1878. case OBJECT_TYPE_CONNECTOR:
  1879. offset = le16_to_cpu(bp->object_info_tbl.v1_1->usConnectorObjectTableOffset);
  1880. break;
  1881. case OBJECT_TYPE_ROUTER:
  1882. offset = le16_to_cpu(bp->object_info_tbl.v1_1->usRouterObjectTableOffset);
  1883. break;
  1884. case OBJECT_TYPE_GENERIC:
  1885. if (bp->object_info_tbl.revision.minor < 3)
  1886. return NULL;
  1887. offset = le16_to_cpu(bp->object_info_tbl.v1_3->usMiscObjectTableOffset);
  1888. break;
  1889. default:
  1890. return NULL;
  1891. }
  1892. offset += bp->object_info_tbl_offset;
  1893. tbl = GET_IMAGE(ATOM_OBJECT_TABLE, offset);
  1894. if (!tbl)
  1895. return NULL;
  1896. for (i = 0; i < tbl->ucNumberOfObjects; i++)
  1897. if (dal_graphics_object_id_is_equal(id,
  1898. object_id_from_bios_object_id(
  1899. le16_to_cpu(tbl->asObjects[i].usObjectID))))
  1900. return &tbl->asObjects[i];
  1901. return NULL;
  1902. }
  1903. static uint32_t get_dest_obj_list(struct bios_parser *bp,
  1904. ATOM_OBJECT *object, uint16_t **id_list)
  1905. {
  1906. uint32_t offset;
  1907. uint8_t *number;
  1908. if (!object) {
  1909. BREAK_TO_DEBUGGER(); /* Invalid object id */
  1910. return 0;
  1911. }
  1912. offset = le16_to_cpu(object->usSrcDstTableOffset)
  1913. + bp->object_info_tbl_offset;
  1914. number = GET_IMAGE(uint8_t, offset);
  1915. if (!number)
  1916. return 0;
  1917. offset += sizeof(uint8_t);
  1918. offset += sizeof(uint16_t) * (*number);
  1919. number = GET_IMAGE(uint8_t, offset);
  1920. if ((!number) || (!*number))
  1921. return 0;
  1922. offset += sizeof(uint8_t);
  1923. *id_list = (uint16_t *)bios_get_image(&bp->base, offset, *number * sizeof(uint16_t));
  1924. if (!*id_list)
  1925. return 0;
  1926. return *number;
  1927. }
  1928. static uint32_t get_src_obj_list(struct bios_parser *bp, ATOM_OBJECT *object,
  1929. uint16_t **id_list)
  1930. {
  1931. uint32_t offset;
  1932. uint8_t *number;
  1933. if (!object) {
  1934. BREAK_TO_DEBUGGER(); /* Invalid object id */
  1935. return 0;
  1936. }
  1937. offset = le16_to_cpu(object->usSrcDstTableOffset)
  1938. + bp->object_info_tbl_offset;
  1939. number = GET_IMAGE(uint8_t, offset);
  1940. if (!number)
  1941. return 0;
  1942. offset += sizeof(uint8_t);
  1943. *id_list = (uint16_t *)bios_get_image(&bp->base, offset, *number * sizeof(uint16_t));
  1944. if (!*id_list)
  1945. return 0;
  1946. return *number;
  1947. }
  1948. static uint32_t get_dst_number_from_object(struct bios_parser *bp,
  1949. ATOM_OBJECT *object)
  1950. {
  1951. uint32_t offset;
  1952. uint8_t *number;
  1953. if (!object) {
  1954. BREAK_TO_DEBUGGER(); /* Invalid encoder object id*/
  1955. return 0;
  1956. }
  1957. offset = le16_to_cpu(object->usSrcDstTableOffset)
  1958. + bp->object_info_tbl_offset;
  1959. number = GET_IMAGE(uint8_t, offset);
  1960. if (!number)
  1961. return 0;
  1962. offset += sizeof(uint8_t);
  1963. offset += sizeof(uint16_t) * (*number);
  1964. number = GET_IMAGE(uint8_t, offset);
  1965. if (!number)
  1966. return 0;
  1967. return *number;
  1968. }
  1969. static struct device_id device_type_from_device_id(uint16_t device_id)
  1970. {
  1971. struct device_id result_device_id;
  1972. switch (device_id) {
  1973. case ATOM_DEVICE_LCD1_SUPPORT:
  1974. result_device_id.device_type = DEVICE_TYPE_LCD;
  1975. result_device_id.enum_id = 1;
  1976. break;
  1977. case ATOM_DEVICE_LCD2_SUPPORT:
  1978. result_device_id.device_type = DEVICE_TYPE_LCD;
  1979. result_device_id.enum_id = 2;
  1980. break;
  1981. case ATOM_DEVICE_CRT1_SUPPORT:
  1982. result_device_id.device_type = DEVICE_TYPE_CRT;
  1983. result_device_id.enum_id = 1;
  1984. break;
  1985. case ATOM_DEVICE_CRT2_SUPPORT:
  1986. result_device_id.device_type = DEVICE_TYPE_CRT;
  1987. result_device_id.enum_id = 2;
  1988. break;
  1989. case ATOM_DEVICE_DFP1_SUPPORT:
  1990. result_device_id.device_type = DEVICE_TYPE_DFP;
  1991. result_device_id.enum_id = 1;
  1992. break;
  1993. case ATOM_DEVICE_DFP2_SUPPORT:
  1994. result_device_id.device_type = DEVICE_TYPE_DFP;
  1995. result_device_id.enum_id = 2;
  1996. break;
  1997. case ATOM_DEVICE_DFP3_SUPPORT:
  1998. result_device_id.device_type = DEVICE_TYPE_DFP;
  1999. result_device_id.enum_id = 3;
  2000. break;
  2001. case ATOM_DEVICE_DFP4_SUPPORT:
  2002. result_device_id.device_type = DEVICE_TYPE_DFP;
  2003. result_device_id.enum_id = 4;
  2004. break;
  2005. case ATOM_DEVICE_DFP5_SUPPORT:
  2006. result_device_id.device_type = DEVICE_TYPE_DFP;
  2007. result_device_id.enum_id = 5;
  2008. break;
  2009. case ATOM_DEVICE_DFP6_SUPPORT:
  2010. result_device_id.device_type = DEVICE_TYPE_DFP;
  2011. result_device_id.enum_id = 6;
  2012. break;
  2013. default:
  2014. BREAK_TO_DEBUGGER(); /* Invalid device Id */
  2015. result_device_id.device_type = DEVICE_TYPE_UNKNOWN;
  2016. result_device_id.enum_id = 0;
  2017. }
  2018. return result_device_id;
  2019. }
  2020. static void get_atom_data_table_revision(
  2021. ATOM_COMMON_TABLE_HEADER *atom_data_tbl,
  2022. struct atom_data_revision *tbl_revision)
  2023. {
  2024. if (!tbl_revision)
  2025. return;
  2026. /* initialize the revision to 0 which is invalid revision */
  2027. tbl_revision->major = 0;
  2028. tbl_revision->minor = 0;
  2029. if (!atom_data_tbl)
  2030. return;
  2031. tbl_revision->major =
  2032. (uint32_t) GET_DATA_TABLE_MAJOR_REVISION(atom_data_tbl);
  2033. tbl_revision->minor =
  2034. (uint32_t) GET_DATA_TABLE_MINOR_REVISION(atom_data_tbl);
  2035. }
  2036. static uint32_t signal_to_ss_id(enum as_signal_type signal)
  2037. {
  2038. uint32_t clk_id_ss = 0;
  2039. switch (signal) {
  2040. case AS_SIGNAL_TYPE_DVI:
  2041. clk_id_ss = ASIC_INTERNAL_SS_ON_TMDS;
  2042. break;
  2043. case AS_SIGNAL_TYPE_HDMI:
  2044. clk_id_ss = ASIC_INTERNAL_SS_ON_HDMI;
  2045. break;
  2046. case AS_SIGNAL_TYPE_LVDS:
  2047. clk_id_ss = ASIC_INTERNAL_SS_ON_LVDS;
  2048. break;
  2049. case AS_SIGNAL_TYPE_DISPLAY_PORT:
  2050. clk_id_ss = ASIC_INTERNAL_SS_ON_DP;
  2051. break;
  2052. case AS_SIGNAL_TYPE_GPU_PLL:
  2053. clk_id_ss = ASIC_INTERNAL_GPUPLL_SS;
  2054. break;
  2055. default:
  2056. break;
  2057. }
  2058. return clk_id_ss;
  2059. }
  2060. static uint32_t get_support_mask_for_device_id(struct device_id device_id)
  2061. {
  2062. enum dal_device_type device_type = device_id.device_type;
  2063. uint32_t enum_id = device_id.enum_id;
  2064. switch (device_type) {
  2065. case DEVICE_TYPE_LCD:
  2066. switch (enum_id) {
  2067. case 1:
  2068. return ATOM_DEVICE_LCD1_SUPPORT;
  2069. case 2:
  2070. return ATOM_DEVICE_LCD2_SUPPORT;
  2071. default:
  2072. break;
  2073. }
  2074. break;
  2075. case DEVICE_TYPE_CRT:
  2076. switch (enum_id) {
  2077. case 1:
  2078. return ATOM_DEVICE_CRT1_SUPPORT;
  2079. case 2:
  2080. return ATOM_DEVICE_CRT2_SUPPORT;
  2081. default:
  2082. break;
  2083. }
  2084. break;
  2085. case DEVICE_TYPE_DFP:
  2086. switch (enum_id) {
  2087. case 1:
  2088. return ATOM_DEVICE_DFP1_SUPPORT;
  2089. case 2:
  2090. return ATOM_DEVICE_DFP2_SUPPORT;
  2091. case 3:
  2092. return ATOM_DEVICE_DFP3_SUPPORT;
  2093. case 4:
  2094. return ATOM_DEVICE_DFP4_SUPPORT;
  2095. case 5:
  2096. return ATOM_DEVICE_DFP5_SUPPORT;
  2097. case 6:
  2098. return ATOM_DEVICE_DFP6_SUPPORT;
  2099. default:
  2100. break;
  2101. }
  2102. break;
  2103. case DEVICE_TYPE_CV:
  2104. switch (enum_id) {
  2105. case 1:
  2106. return ATOM_DEVICE_CV_SUPPORT;
  2107. default:
  2108. break;
  2109. }
  2110. break;
  2111. case DEVICE_TYPE_TV:
  2112. switch (enum_id) {
  2113. case 1:
  2114. return ATOM_DEVICE_TV1_SUPPORT;
  2115. default:
  2116. break;
  2117. }
  2118. break;
  2119. default:
  2120. break;
  2121. };
  2122. /* Unidentified device ID, return empty support mask. */
  2123. return 0;
  2124. }
  2125. /**
  2126. * HwContext interface for writing MM registers
  2127. */
  2128. static bool i2c_read(
  2129. struct bios_parser *bp,
  2130. struct graphics_object_i2c_info *i2c_info,
  2131. uint8_t *buffer,
  2132. uint32_t length)
  2133. {
  2134. struct ddc *ddc;
  2135. uint8_t offset[2] = { 0, 0 };
  2136. bool result = false;
  2137. struct i2c_command cmd;
  2138. struct gpio_ddc_hw_info hw_info = {
  2139. i2c_info->i2c_hw_assist,
  2140. i2c_info->i2c_line };
  2141. ddc = dal_gpio_create_ddc(bp->base.ctx->gpio_service,
  2142. i2c_info->gpio_info.clk_a_register_index,
  2143. (1 << i2c_info->gpio_info.clk_a_shift), &hw_info);
  2144. if (!ddc)
  2145. return result;
  2146. /*Using SW engine */
  2147. cmd.engine = I2C_COMMAND_ENGINE_SW;
  2148. cmd.speed = ddc->ctx->dc->caps.i2c_speed_in_khz;
  2149. {
  2150. struct i2c_payload payloads[] = {
  2151. {
  2152. .address = i2c_info->i2c_slave_address >> 1,
  2153. .data = offset,
  2154. .length = sizeof(offset),
  2155. .write = true
  2156. },
  2157. {
  2158. .address = i2c_info->i2c_slave_address >> 1,
  2159. .data = buffer,
  2160. .length = length,
  2161. .write = false
  2162. }
  2163. };
  2164. cmd.payloads = payloads;
  2165. cmd.number_of_payloads = ARRAY_SIZE(payloads);
  2166. /* TODO route this through drm i2c_adapter */
  2167. result = dal_i2caux_submit_i2c_command(
  2168. ddc->ctx->i2caux,
  2169. ddc,
  2170. &cmd);
  2171. }
  2172. dal_gpio_destroy_ddc(&ddc);
  2173. return result;
  2174. }
  2175. /**
  2176. * Read external display connection info table through i2c.
  2177. * validate the GUID and checksum.
  2178. *
  2179. * @return enum bp_result whether all data was sucessfully read
  2180. */
  2181. static enum bp_result get_ext_display_connection_info(
  2182. struct bios_parser *bp,
  2183. ATOM_OBJECT *opm_object,
  2184. ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO *ext_display_connection_info_tbl)
  2185. {
  2186. bool config_tbl_present = false;
  2187. ATOM_I2C_RECORD *i2c_record = NULL;
  2188. uint32_t i = 0;
  2189. if (opm_object == NULL)
  2190. return BP_RESULT_BADINPUT;
  2191. i2c_record = get_i2c_record(bp, opm_object);
  2192. if (i2c_record != NULL) {
  2193. ATOM_GPIO_I2C_INFO *gpio_i2c_header;
  2194. struct graphics_object_i2c_info i2c_info;
  2195. gpio_i2c_header = GET_IMAGE(ATOM_GPIO_I2C_INFO,
  2196. bp->master_data_tbl->ListOfDataTables.GPIO_I2C_Info);
  2197. if (NULL == gpio_i2c_header)
  2198. return BP_RESULT_BADBIOSTABLE;
  2199. if (get_gpio_i2c_info(bp, i2c_record, &i2c_info) !=
  2200. BP_RESULT_OK)
  2201. return BP_RESULT_BADBIOSTABLE;
  2202. if (i2c_read(bp,
  2203. &i2c_info,
  2204. (uint8_t *)ext_display_connection_info_tbl,
  2205. sizeof(ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO))) {
  2206. config_tbl_present = true;
  2207. }
  2208. }
  2209. /* Validate GUID */
  2210. if (config_tbl_present)
  2211. for (i = 0; i < NUMBER_OF_UCHAR_FOR_GUID; i++) {
  2212. if (ext_display_connection_info_tbl->ucGuid[i]
  2213. != ext_display_connection_guid[i]) {
  2214. config_tbl_present = false;
  2215. break;
  2216. }
  2217. }
  2218. /* Validate checksum */
  2219. if (config_tbl_present) {
  2220. uint8_t check_sum = 0;
  2221. uint8_t *buf =
  2222. (uint8_t *)ext_display_connection_info_tbl;
  2223. for (i = 0; i < sizeof(ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO);
  2224. i++) {
  2225. check_sum += buf[i];
  2226. }
  2227. if (check_sum != 0)
  2228. config_tbl_present = false;
  2229. }
  2230. if (config_tbl_present)
  2231. return BP_RESULT_OK;
  2232. else
  2233. return BP_RESULT_FAILURE;
  2234. }
  2235. /*
  2236. * Gets the first device ID in the same group as the given ID for enumerating.
  2237. * For instance, if any DFP device ID is passed, returns the device ID for DFP1.
  2238. *
  2239. * The first device ID in the same group as the passed device ID, or 0 if no
  2240. * matching device group found.
  2241. */
  2242. static uint32_t enum_first_device_id(uint32_t dev_id)
  2243. {
  2244. /* Return the first in the group that this ID belongs to. */
  2245. if (dev_id & ATOM_DEVICE_CRT_SUPPORT)
  2246. return ATOM_DEVICE_CRT1_SUPPORT;
  2247. else if (dev_id & ATOM_DEVICE_DFP_SUPPORT)
  2248. return ATOM_DEVICE_DFP1_SUPPORT;
  2249. else if (dev_id & ATOM_DEVICE_LCD_SUPPORT)
  2250. return ATOM_DEVICE_LCD1_SUPPORT;
  2251. else if (dev_id & ATOM_DEVICE_TV_SUPPORT)
  2252. return ATOM_DEVICE_TV1_SUPPORT;
  2253. else if (dev_id & ATOM_DEVICE_CV_SUPPORT)
  2254. return ATOM_DEVICE_CV_SUPPORT;
  2255. /* No group found for this device ID. */
  2256. dm_error("%s: incorrect input %d\n", __func__, dev_id);
  2257. /* No matching support flag for given device ID */
  2258. return 0;
  2259. }
  2260. /*
  2261. * Gets the next device ID in the group for a given device ID.
  2262. *
  2263. * The current device ID being enumerated on.
  2264. *
  2265. * The next device ID in the group, or 0 if no device exists.
  2266. */
  2267. static uint32_t enum_next_dev_id(uint32_t dev_id)
  2268. {
  2269. /* Get next device ID in the group. */
  2270. switch (dev_id) {
  2271. case ATOM_DEVICE_CRT1_SUPPORT:
  2272. return ATOM_DEVICE_CRT2_SUPPORT;
  2273. case ATOM_DEVICE_LCD1_SUPPORT:
  2274. return ATOM_DEVICE_LCD2_SUPPORT;
  2275. case ATOM_DEVICE_DFP1_SUPPORT:
  2276. return ATOM_DEVICE_DFP2_SUPPORT;
  2277. case ATOM_DEVICE_DFP2_SUPPORT:
  2278. return ATOM_DEVICE_DFP3_SUPPORT;
  2279. case ATOM_DEVICE_DFP3_SUPPORT:
  2280. return ATOM_DEVICE_DFP4_SUPPORT;
  2281. case ATOM_DEVICE_DFP4_SUPPORT:
  2282. return ATOM_DEVICE_DFP5_SUPPORT;
  2283. case ATOM_DEVICE_DFP5_SUPPORT:
  2284. return ATOM_DEVICE_DFP6_SUPPORT;
  2285. }
  2286. /* Done enumerating through devices. */
  2287. return 0;
  2288. }
  2289. /*
  2290. * Returns the new device tag record for patched BIOS object.
  2291. *
  2292. * [IN] pExtDisplayPath - External display path to copy device tag from.
  2293. * [IN] deviceSupport - Bit vector for device ID support flags.
  2294. * [OUT] pDeviceTag - Device tag structure to fill with patched data.
  2295. *
  2296. * True if a compatible device ID was found, false otherwise.
  2297. */
  2298. static bool get_patched_device_tag(
  2299. struct bios_parser *bp,
  2300. EXT_DISPLAY_PATH *ext_display_path,
  2301. uint32_t device_support,
  2302. ATOM_CONNECTOR_DEVICE_TAG *device_tag)
  2303. {
  2304. uint32_t dev_id;
  2305. /* Use fallback behaviour if not supported. */
  2306. if (!bp->remap_device_tags) {
  2307. device_tag->ulACPIDeviceEnum =
  2308. cpu_to_le32((uint32_t) le16_to_cpu(ext_display_path->usDeviceACPIEnum));
  2309. device_tag->usDeviceID =
  2310. cpu_to_le16(le16_to_cpu(ext_display_path->usDeviceTag));
  2311. return true;
  2312. }
  2313. /* Find the first unused in the same group. */
  2314. dev_id = enum_first_device_id(le16_to_cpu(ext_display_path->usDeviceTag));
  2315. while (dev_id != 0) {
  2316. /* Assign this device ID if supported. */
  2317. if ((device_support & dev_id) != 0) {
  2318. device_tag->ulACPIDeviceEnum =
  2319. cpu_to_le32((uint32_t) le16_to_cpu(ext_display_path->usDeviceACPIEnum));
  2320. device_tag->usDeviceID = cpu_to_le16((USHORT) dev_id);
  2321. return true;
  2322. }
  2323. dev_id = enum_next_dev_id(dev_id);
  2324. }
  2325. /* No compatible device ID found. */
  2326. return false;
  2327. }
  2328. /*
  2329. * Adds a device tag to a BIOS object's device tag record if there is
  2330. * matching device ID supported.
  2331. *
  2332. * pObject - Pointer to the BIOS object to add the device tag to.
  2333. * pExtDisplayPath - Display path to retrieve base device ID from.
  2334. * pDeviceSupport - Pointer to bit vector for supported device IDs.
  2335. */
  2336. static void add_device_tag_from_ext_display_path(
  2337. struct bios_parser *bp,
  2338. ATOM_OBJECT *object,
  2339. EXT_DISPLAY_PATH *ext_display_path,
  2340. uint32_t *device_support)
  2341. {
  2342. /* Get device tag record for object. */
  2343. ATOM_CONNECTOR_DEVICE_TAG *device_tag = NULL;
  2344. ATOM_CONNECTOR_DEVICE_TAG_RECORD *device_tag_record = NULL;
  2345. enum bp_result result =
  2346. bios_parser_get_device_tag_record(
  2347. bp, object, &device_tag_record);
  2348. if ((le16_to_cpu(ext_display_path->usDeviceTag) != CONNECTOR_OBJECT_ID_NONE)
  2349. && (result == BP_RESULT_OK)) {
  2350. uint8_t index;
  2351. if ((device_tag_record->ucNumberOfDevice == 1) &&
  2352. (le16_to_cpu(device_tag_record->asDeviceTag[0].usDeviceID) == 0)) {
  2353. /*Workaround bug in current VBIOS releases where
  2354. * ucNumberOfDevice = 1 but there is no actual device
  2355. * tag data. This w/a is temporary until the updated
  2356. * VBIOS is distributed. */
  2357. device_tag_record->ucNumberOfDevice =
  2358. device_tag_record->ucNumberOfDevice - 1;
  2359. }
  2360. /* Attempt to find a matching device ID. */
  2361. index = device_tag_record->ucNumberOfDevice;
  2362. device_tag = &device_tag_record->asDeviceTag[index];
  2363. if (get_patched_device_tag(
  2364. bp,
  2365. ext_display_path,
  2366. *device_support,
  2367. device_tag)) {
  2368. /* Update cached device support to remove assigned ID.
  2369. */
  2370. *device_support &= ~le16_to_cpu(device_tag->usDeviceID);
  2371. device_tag_record->ucNumberOfDevice++;
  2372. }
  2373. }
  2374. }
  2375. /*
  2376. * Read out a single EXT_DISPLAY_PATH from the external display connection info
  2377. * table. The specific entry in the table is determined by the enum_id passed
  2378. * in.
  2379. *
  2380. * EXT_DISPLAY_PATH describing a single Configuration table entry
  2381. */
  2382. #define INVALID_CONNECTOR 0xffff
  2383. static EXT_DISPLAY_PATH *get_ext_display_path_entry(
  2384. ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO *config_table,
  2385. uint32_t bios_object_id)
  2386. {
  2387. EXT_DISPLAY_PATH *ext_display_path;
  2388. uint32_t ext_display_path_index =
  2389. ((bios_object_id & ENUM_ID_MASK) >> ENUM_ID_SHIFT) - 1;
  2390. if (ext_display_path_index >= MAX_NUMBER_OF_EXT_DISPLAY_PATH)
  2391. return NULL;
  2392. ext_display_path = &config_table->sPath[ext_display_path_index];
  2393. if (le16_to_cpu(ext_display_path->usDeviceConnector) == INVALID_CONNECTOR)
  2394. ext_display_path->usDeviceConnector = cpu_to_le16(0);
  2395. return ext_display_path;
  2396. }
  2397. /*
  2398. * Get AUX/DDC information of input object id
  2399. *
  2400. * search all records to find the ATOM_CONNECTOR_AUXDDC_LUT_RECORD_TYPE record
  2401. * IR
  2402. */
  2403. static ATOM_CONNECTOR_AUXDDC_LUT_RECORD *get_ext_connector_aux_ddc_lut_record(
  2404. struct bios_parser *bp,
  2405. ATOM_OBJECT *object)
  2406. {
  2407. uint32_t offset;
  2408. ATOM_COMMON_RECORD_HEADER *header;
  2409. if (!object) {
  2410. BREAK_TO_DEBUGGER();
  2411. /* Invalid object */
  2412. return NULL;
  2413. }
  2414. offset = le16_to_cpu(object->usRecordOffset)
  2415. + bp->object_info_tbl_offset;
  2416. for (;;) {
  2417. header = GET_IMAGE(ATOM_COMMON_RECORD_HEADER, offset);
  2418. if (!header)
  2419. return NULL;
  2420. if (LAST_RECORD_TYPE == header->ucRecordType ||
  2421. 0 == header->ucRecordSize)
  2422. break;
  2423. if (ATOM_CONNECTOR_AUXDDC_LUT_RECORD_TYPE ==
  2424. header->ucRecordType &&
  2425. sizeof(ATOM_CONNECTOR_AUXDDC_LUT_RECORD) <=
  2426. header->ucRecordSize)
  2427. return (ATOM_CONNECTOR_AUXDDC_LUT_RECORD *)(header);
  2428. offset += header->ucRecordSize;
  2429. }
  2430. return NULL;
  2431. }
  2432. /*
  2433. * Get AUX/DDC information of input object id
  2434. *
  2435. * search all records to find the ATOM_CONNECTOR_AUXDDC_LUT_RECORD_TYPE record
  2436. * IR
  2437. */
  2438. static ATOM_CONNECTOR_HPDPIN_LUT_RECORD *get_ext_connector_hpd_pin_lut_record(
  2439. struct bios_parser *bp,
  2440. ATOM_OBJECT *object)
  2441. {
  2442. uint32_t offset;
  2443. ATOM_COMMON_RECORD_HEADER *header;
  2444. if (!object) {
  2445. BREAK_TO_DEBUGGER();
  2446. /* Invalid object */
  2447. return NULL;
  2448. }
  2449. offset = le16_to_cpu(object->usRecordOffset)
  2450. + bp->object_info_tbl_offset;
  2451. for (;;) {
  2452. header = GET_IMAGE(ATOM_COMMON_RECORD_HEADER, offset);
  2453. if (!header)
  2454. return NULL;
  2455. if (LAST_RECORD_TYPE == header->ucRecordType ||
  2456. 0 == header->ucRecordSize)
  2457. break;
  2458. if (ATOM_CONNECTOR_HPDPIN_LUT_RECORD_TYPE ==
  2459. header->ucRecordType &&
  2460. sizeof(ATOM_CONNECTOR_HPDPIN_LUT_RECORD) <=
  2461. header->ucRecordSize)
  2462. return (ATOM_CONNECTOR_HPDPIN_LUT_RECORD *)header;
  2463. offset += header->ucRecordSize;
  2464. }
  2465. return NULL;
  2466. }
  2467. /*
  2468. * Check whether we need to patch the VBIOS connector info table with
  2469. * data from an external display connection info table. This is
  2470. * necessary to support MXM boards with an OPM (output personality
  2471. * module). With these designs, the VBIOS connector info table
  2472. * specifies an MXM_CONNECTOR with a unique ID. The driver retrieves
  2473. * the external connection info table through i2c and then looks up the
  2474. * connector ID to find the real connector type (e.g. DFP1).
  2475. *
  2476. */
  2477. static enum bp_result patch_bios_image_from_ext_display_connection_info(
  2478. struct bios_parser *bp)
  2479. {
  2480. ATOM_OBJECT_TABLE *connector_tbl;
  2481. uint32_t connector_tbl_offset;
  2482. struct graphics_object_id object_id;
  2483. ATOM_OBJECT *object;
  2484. ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO ext_display_connection_info_tbl;
  2485. EXT_DISPLAY_PATH *ext_display_path;
  2486. ATOM_CONNECTOR_AUXDDC_LUT_RECORD *aux_ddc_lut_record = NULL;
  2487. ATOM_I2C_RECORD *i2c_record = NULL;
  2488. ATOM_CONNECTOR_HPDPIN_LUT_RECORD *hpd_pin_lut_record = NULL;
  2489. ATOM_HPD_INT_RECORD *hpd_record = NULL;
  2490. ATOM_OBJECT_TABLE *encoder_table;
  2491. uint32_t encoder_table_offset;
  2492. ATOM_OBJECT *opm_object = NULL;
  2493. uint32_t i = 0;
  2494. struct graphics_object_id opm_object_id =
  2495. dal_graphics_object_id_init(
  2496. GENERIC_ID_MXM_OPM,
  2497. ENUM_ID_1,
  2498. OBJECT_TYPE_GENERIC);
  2499. ATOM_CONNECTOR_DEVICE_TAG_RECORD *dev_tag_record;
  2500. uint32_t cached_device_support =
  2501. le16_to_cpu(bp->object_info_tbl.v1_1->usDeviceSupport);
  2502. uint32_t dst_number;
  2503. uint16_t *dst_object_id_list;
  2504. opm_object = get_bios_object(bp, opm_object_id);
  2505. if (!opm_object)
  2506. return BP_RESULT_UNSUPPORTED;
  2507. memset(&ext_display_connection_info_tbl, 0,
  2508. sizeof(ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO));
  2509. connector_tbl_offset = bp->object_info_tbl_offset
  2510. + le16_to_cpu(bp->object_info_tbl.v1_1->usConnectorObjectTableOffset);
  2511. connector_tbl = GET_IMAGE(ATOM_OBJECT_TABLE, connector_tbl_offset);
  2512. /* Read Connector info table from EEPROM through i2c */
  2513. if (get_ext_display_connection_info(bp,
  2514. opm_object,
  2515. &ext_display_connection_info_tbl) != BP_RESULT_OK) {
  2516. dm_logger_write(bp->base.ctx->logger, LOG_WARNING,
  2517. "%s: Failed to read Connection Info Table", __func__);
  2518. return BP_RESULT_UNSUPPORTED;
  2519. }
  2520. /* Get pointer to AUX/DDC and HPD LUTs */
  2521. aux_ddc_lut_record =
  2522. get_ext_connector_aux_ddc_lut_record(bp, opm_object);
  2523. hpd_pin_lut_record =
  2524. get_ext_connector_hpd_pin_lut_record(bp, opm_object);
  2525. if ((aux_ddc_lut_record == NULL) || (hpd_pin_lut_record == NULL))
  2526. return BP_RESULT_UNSUPPORTED;
  2527. /* Cache support bits for currently unmapped device types. */
  2528. if (bp->remap_device_tags) {
  2529. for (i = 0; i < connector_tbl->ucNumberOfObjects; ++i) {
  2530. uint32_t j;
  2531. /* Remove support for all non-MXM connectors. */
  2532. object = &connector_tbl->asObjects[i];
  2533. object_id = object_id_from_bios_object_id(
  2534. le16_to_cpu(object->usObjectID));
  2535. if ((OBJECT_TYPE_CONNECTOR != object_id.type) ||
  2536. (CONNECTOR_ID_MXM == object_id.id))
  2537. continue;
  2538. /* Remove support for all device tags. */
  2539. if (bios_parser_get_device_tag_record(
  2540. bp, object, &dev_tag_record) != BP_RESULT_OK)
  2541. continue;
  2542. for (j = 0; j < dev_tag_record->ucNumberOfDevice; ++j) {
  2543. ATOM_CONNECTOR_DEVICE_TAG *device_tag =
  2544. &dev_tag_record->asDeviceTag[j];
  2545. cached_device_support &=
  2546. ~le16_to_cpu(device_tag->usDeviceID);
  2547. }
  2548. }
  2549. }
  2550. /* Find all MXM connector objects and patch them with connector info
  2551. * from the external display connection info table. */
  2552. for (i = 0; i < connector_tbl->ucNumberOfObjects; i++) {
  2553. uint32_t j;
  2554. object = &connector_tbl->asObjects[i];
  2555. object_id = object_id_from_bios_object_id(le16_to_cpu(object->usObjectID));
  2556. if ((OBJECT_TYPE_CONNECTOR != object_id.type) ||
  2557. (CONNECTOR_ID_MXM != object_id.id))
  2558. continue;
  2559. /* Get the correct connection info table entry based on the enum
  2560. * id. */
  2561. ext_display_path = get_ext_display_path_entry(
  2562. &ext_display_connection_info_tbl,
  2563. le16_to_cpu(object->usObjectID));
  2564. if (!ext_display_path)
  2565. return BP_RESULT_FAILURE;
  2566. /* Patch device connector ID */
  2567. object->usObjectID =
  2568. cpu_to_le16(le16_to_cpu(ext_display_path->usDeviceConnector));
  2569. /* Patch device tag, ulACPIDeviceEnum. */
  2570. add_device_tag_from_ext_display_path(
  2571. bp,
  2572. object,
  2573. ext_display_path,
  2574. &cached_device_support);
  2575. /* Patch HPD info */
  2576. if (ext_display_path->ucExtHPDPINLutIndex <
  2577. MAX_NUMBER_OF_EXT_HPDPIN_LUT_ENTRIES) {
  2578. hpd_record = get_hpd_record(bp, object);
  2579. if (hpd_record) {
  2580. uint8_t index =
  2581. ext_display_path->ucExtHPDPINLutIndex;
  2582. hpd_record->ucHPDIntGPIOID =
  2583. hpd_pin_lut_record->ucHPDPINMap[index];
  2584. } else {
  2585. BREAK_TO_DEBUGGER();
  2586. /* Invalid hpd record */
  2587. return BP_RESULT_FAILURE;
  2588. }
  2589. }
  2590. /* Patch I2C/AUX info */
  2591. if (ext_display_path->ucExtHPDPINLutIndex <
  2592. MAX_NUMBER_OF_EXT_AUXDDC_LUT_ENTRIES) {
  2593. i2c_record = get_i2c_record(bp, object);
  2594. if (i2c_record) {
  2595. uint8_t index =
  2596. ext_display_path->ucExtAUXDDCLutIndex;
  2597. i2c_record->sucI2cId =
  2598. aux_ddc_lut_record->ucAUXDDCMap[index];
  2599. } else {
  2600. BREAK_TO_DEBUGGER();
  2601. /* Invalid I2C record */
  2602. return BP_RESULT_FAILURE;
  2603. }
  2604. }
  2605. /* Merge with other MXM connectors that map to the same physical
  2606. * connector. */
  2607. for (j = i + 1;
  2608. j < connector_tbl->ucNumberOfObjects; j++) {
  2609. ATOM_OBJECT *next_object;
  2610. struct graphics_object_id next_object_id;
  2611. EXT_DISPLAY_PATH *next_ext_display_path;
  2612. next_object = &connector_tbl->asObjects[j];
  2613. next_object_id = object_id_from_bios_object_id(
  2614. le16_to_cpu(next_object->usObjectID));
  2615. if ((OBJECT_TYPE_CONNECTOR != next_object_id.type) &&
  2616. (CONNECTOR_ID_MXM == next_object_id.id))
  2617. continue;
  2618. next_ext_display_path = get_ext_display_path_entry(
  2619. &ext_display_connection_info_tbl,
  2620. le16_to_cpu(next_object->usObjectID));
  2621. if (next_ext_display_path == NULL)
  2622. return BP_RESULT_FAILURE;
  2623. /* Merge if using same connector. */
  2624. if ((le16_to_cpu(next_ext_display_path->usDeviceConnector) ==
  2625. le16_to_cpu(ext_display_path->usDeviceConnector)) &&
  2626. (le16_to_cpu(ext_display_path->usDeviceConnector) != 0)) {
  2627. /* Clear duplicate connector from table. */
  2628. next_object->usObjectID = cpu_to_le16(0);
  2629. add_device_tag_from_ext_display_path(
  2630. bp,
  2631. object,
  2632. ext_display_path,
  2633. &cached_device_support);
  2634. }
  2635. }
  2636. }
  2637. /* Find all encoders which have an MXM object as their destination.
  2638. * Replace the MXM object with the real connector Id from the external
  2639. * display connection info table */
  2640. encoder_table_offset = bp->object_info_tbl_offset
  2641. + le16_to_cpu(bp->object_info_tbl.v1_1->usEncoderObjectTableOffset);
  2642. encoder_table = GET_IMAGE(ATOM_OBJECT_TABLE, encoder_table_offset);
  2643. for (i = 0; i < encoder_table->ucNumberOfObjects; i++) {
  2644. uint32_t j;
  2645. object = &encoder_table->asObjects[i];
  2646. dst_number = get_dest_obj_list(bp, object, &dst_object_id_list);
  2647. for (j = 0; j < dst_number; j++) {
  2648. object_id = object_id_from_bios_object_id(
  2649. dst_object_id_list[j]);
  2650. if ((OBJECT_TYPE_CONNECTOR != object_id.type) ||
  2651. (CONNECTOR_ID_MXM != object_id.id))
  2652. continue;
  2653. /* Get the correct connection info table entry based on
  2654. * the enum id. */
  2655. ext_display_path =
  2656. get_ext_display_path_entry(
  2657. &ext_display_connection_info_tbl,
  2658. dst_object_id_list[j]);
  2659. if (ext_display_path == NULL)
  2660. return BP_RESULT_FAILURE;
  2661. dst_object_id_list[j] =
  2662. le16_to_cpu(ext_display_path->usDeviceConnector);
  2663. }
  2664. }
  2665. return BP_RESULT_OK;
  2666. }
  2667. /*
  2668. * Check whether we need to patch the VBIOS connector info table with
  2669. * data from an external display connection info table. This is
  2670. * necessary to support MXM boards with an OPM (output personality
  2671. * module). With these designs, the VBIOS connector info table
  2672. * specifies an MXM_CONNECTOR with a unique ID. The driver retrieves
  2673. * the external connection info table through i2c and then looks up the
  2674. * connector ID to find the real connector type (e.g. DFP1).
  2675. *
  2676. */
  2677. static void process_ext_display_connection_info(struct bios_parser *bp)
  2678. {
  2679. ATOM_OBJECT_TABLE *connector_tbl;
  2680. uint32_t connector_tbl_offset;
  2681. struct graphics_object_id object_id;
  2682. ATOM_OBJECT *object;
  2683. bool mxm_connector_found = false;
  2684. bool null_entry_found = false;
  2685. uint32_t i = 0;
  2686. connector_tbl_offset = bp->object_info_tbl_offset +
  2687. le16_to_cpu(bp->object_info_tbl.v1_1->usConnectorObjectTableOffset);
  2688. connector_tbl = GET_IMAGE(ATOM_OBJECT_TABLE, connector_tbl_offset);
  2689. /* Look for MXM connectors to determine whether we need patch the VBIOS
  2690. * connector info table. Look for null entries to determine whether we
  2691. * need to compact connector table. */
  2692. for (i = 0; i < connector_tbl->ucNumberOfObjects; i++) {
  2693. object = &connector_tbl->asObjects[i];
  2694. object_id = object_id_from_bios_object_id(le16_to_cpu(object->usObjectID));
  2695. if ((OBJECT_TYPE_CONNECTOR == object_id.type) &&
  2696. (CONNECTOR_ID_MXM == object_id.id)) {
  2697. /* Once we found MXM connector - we can break */
  2698. mxm_connector_found = true;
  2699. break;
  2700. } else if (OBJECT_TYPE_CONNECTOR != object_id.type) {
  2701. /* We need to continue looping - to check if MXM
  2702. * connector present */
  2703. null_entry_found = true;
  2704. }
  2705. }
  2706. /* Patch BIOS image */
  2707. if (mxm_connector_found || null_entry_found) {
  2708. uint32_t connectors_num = 0;
  2709. uint8_t *original_bios;
  2710. /* Step 1: Replace bios image with the new copy which will be
  2711. * patched */
  2712. bp->base.bios_local_image = kzalloc(bp->base.bios_size,
  2713. GFP_KERNEL);
  2714. if (bp->base.bios_local_image == NULL) {
  2715. BREAK_TO_DEBUGGER();
  2716. /* Failed to alloc bp->base.bios_local_image */
  2717. return;
  2718. }
  2719. memmove(bp->base.bios_local_image, bp->base.bios, bp->base.bios_size);
  2720. original_bios = bp->base.bios;
  2721. bp->base.bios = bp->base.bios_local_image;
  2722. connector_tbl =
  2723. GET_IMAGE(ATOM_OBJECT_TABLE, connector_tbl_offset);
  2724. /* Step 2: (only if MXM connector found) Patch BIOS image with
  2725. * info from external module */
  2726. if (mxm_connector_found &&
  2727. patch_bios_image_from_ext_display_connection_info(bp) !=
  2728. BP_RESULT_OK) {
  2729. /* Patching the bios image has failed. We will copy
  2730. * again original image provided and afterwards
  2731. * only remove null entries */
  2732. memmove(
  2733. bp->base.bios_local_image,
  2734. original_bios,
  2735. bp->base.bios_size);
  2736. }
  2737. /* Step 3: Compact connector table (remove null entries, valid
  2738. * entries moved to beginning) */
  2739. for (i = 0; i < connector_tbl->ucNumberOfObjects; i++) {
  2740. object = &connector_tbl->asObjects[i];
  2741. object_id = object_id_from_bios_object_id(
  2742. le16_to_cpu(object->usObjectID));
  2743. if (OBJECT_TYPE_CONNECTOR != object_id.type)
  2744. continue;
  2745. if (i != connectors_num) {
  2746. memmove(
  2747. &connector_tbl->
  2748. asObjects[connectors_num],
  2749. object,
  2750. sizeof(ATOM_OBJECT));
  2751. }
  2752. ++connectors_num;
  2753. }
  2754. connector_tbl->ucNumberOfObjects = (uint8_t)connectors_num;
  2755. }
  2756. }
  2757. static void bios_parser_post_init(struct dc_bios *dcb)
  2758. {
  2759. struct bios_parser *bp = BP_FROM_DCB(dcb);
  2760. process_ext_display_connection_info(bp);
  2761. }
  2762. /**
  2763. * bios_parser_set_scratch_critical_state
  2764. *
  2765. * @brief
  2766. * update critical state bit in VBIOS scratch register
  2767. *
  2768. * @param
  2769. * bool - to set or reset state
  2770. */
  2771. static void bios_parser_set_scratch_critical_state(
  2772. struct dc_bios *dcb,
  2773. bool state)
  2774. {
  2775. bios_set_scratch_critical_state(dcb, state);
  2776. }
  2777. /*
  2778. * get_integrated_info_v8
  2779. *
  2780. * @brief
  2781. * Get V8 integrated BIOS information
  2782. *
  2783. * @param
  2784. * bios_parser *bp - [in]BIOS parser handler to get master data table
  2785. * integrated_info *info - [out] store and output integrated info
  2786. *
  2787. * @return
  2788. * enum bp_result - BP_RESULT_OK if information is available,
  2789. * BP_RESULT_BADBIOSTABLE otherwise.
  2790. */
  2791. static enum bp_result get_integrated_info_v8(
  2792. struct bios_parser *bp,
  2793. struct integrated_info *info)
  2794. {
  2795. ATOM_INTEGRATED_SYSTEM_INFO_V1_8 *info_v8;
  2796. uint32_t i;
  2797. info_v8 = GET_IMAGE(ATOM_INTEGRATED_SYSTEM_INFO_V1_8,
  2798. bp->master_data_tbl->ListOfDataTables.IntegratedSystemInfo);
  2799. if (info_v8 == NULL)
  2800. return BP_RESULT_BADBIOSTABLE;
  2801. info->boot_up_engine_clock = le32_to_cpu(info_v8->ulBootUpEngineClock) * 10;
  2802. info->dentist_vco_freq = le32_to_cpu(info_v8->ulDentistVCOFreq) * 10;
  2803. info->boot_up_uma_clock = le32_to_cpu(info_v8->ulBootUpUMAClock) * 10;
  2804. for (i = 0; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
  2805. /* Convert [10KHz] into [KHz] */
  2806. info->disp_clk_voltage[i].max_supported_clk =
  2807. le32_to_cpu(info_v8->sDISPCLK_Voltage[i].
  2808. ulMaximumSupportedCLK) * 10;
  2809. info->disp_clk_voltage[i].voltage_index =
  2810. le32_to_cpu(info_v8->sDISPCLK_Voltage[i].ulVoltageIndex);
  2811. }
  2812. info->boot_up_req_display_vector =
  2813. le32_to_cpu(info_v8->ulBootUpReqDisplayVector);
  2814. info->gpu_cap_info =
  2815. le32_to_cpu(info_v8->ulGPUCapInfo);
  2816. /*
  2817. * system_config: Bit[0] = 0 : PCIE power gating disabled
  2818. * = 1 : PCIE power gating enabled
  2819. * Bit[1] = 0 : DDR-PLL shut down disabled
  2820. * = 1 : DDR-PLL shut down enabled
  2821. * Bit[2] = 0 : DDR-PLL power down disabled
  2822. * = 1 : DDR-PLL power down enabled
  2823. */
  2824. info->system_config = le32_to_cpu(info_v8->ulSystemConfig);
  2825. info->cpu_cap_info = le32_to_cpu(info_v8->ulCPUCapInfo);
  2826. info->boot_up_nb_voltage =
  2827. le16_to_cpu(info_v8->usBootUpNBVoltage);
  2828. info->ext_disp_conn_info_offset =
  2829. le16_to_cpu(info_v8->usExtDispConnInfoOffset);
  2830. info->memory_type = info_v8->ucMemoryType;
  2831. info->ma_channel_number = info_v8->ucUMAChannelNumber;
  2832. info->gmc_restore_reset_time =
  2833. le32_to_cpu(info_v8->ulGMCRestoreResetTime);
  2834. info->minimum_n_clk =
  2835. le32_to_cpu(info_v8->ulNbpStateNClkFreq[0]);
  2836. for (i = 1; i < 4; ++i)
  2837. info->minimum_n_clk =
  2838. info->minimum_n_clk < le32_to_cpu(info_v8->ulNbpStateNClkFreq[i]) ?
  2839. info->minimum_n_clk : le32_to_cpu(info_v8->ulNbpStateNClkFreq[i]);
  2840. info->idle_n_clk = le32_to_cpu(info_v8->ulIdleNClk);
  2841. info->ddr_dll_power_up_time =
  2842. le32_to_cpu(info_v8->ulDDR_DLL_PowerUpTime);
  2843. info->ddr_pll_power_up_time =
  2844. le32_to_cpu(info_v8->ulDDR_PLL_PowerUpTime);
  2845. info->pcie_clk_ss_type = le16_to_cpu(info_v8->usPCIEClkSSType);
  2846. info->lvds_ss_percentage =
  2847. le16_to_cpu(info_v8->usLvdsSSPercentage);
  2848. info->lvds_sspread_rate_in_10hz =
  2849. le16_to_cpu(info_v8->usLvdsSSpreadRateIn10Hz);
  2850. info->hdmi_ss_percentage =
  2851. le16_to_cpu(info_v8->usHDMISSPercentage);
  2852. info->hdmi_sspread_rate_in_10hz =
  2853. le16_to_cpu(info_v8->usHDMISSpreadRateIn10Hz);
  2854. info->dvi_ss_percentage =
  2855. le16_to_cpu(info_v8->usDVISSPercentage);
  2856. info->dvi_sspread_rate_in_10_hz =
  2857. le16_to_cpu(info_v8->usDVISSpreadRateIn10Hz);
  2858. info->max_lvds_pclk_freq_in_single_link =
  2859. le16_to_cpu(info_v8->usMaxLVDSPclkFreqInSingleLink);
  2860. info->lvds_misc = info_v8->ucLvdsMisc;
  2861. info->lvds_pwr_on_seq_dig_on_to_de_in_4ms =
  2862. info_v8->ucLVDSPwrOnSeqDIGONtoDE_in4Ms;
  2863. info->lvds_pwr_on_seq_de_to_vary_bl_in_4ms =
  2864. info_v8->ucLVDSPwrOnSeqDEtoVARY_BL_in4Ms;
  2865. info->lvds_pwr_on_seq_vary_bl_to_blon_in_4ms =
  2866. info_v8->ucLVDSPwrOnSeqVARY_BLtoBLON_in4Ms;
  2867. info->lvds_pwr_off_seq_vary_bl_to_de_in4ms =
  2868. info_v8->ucLVDSPwrOffSeqVARY_BLtoDE_in4Ms;
  2869. info->lvds_pwr_off_seq_de_to_dig_on_in4ms =
  2870. info_v8->ucLVDSPwrOffSeqDEtoDIGON_in4Ms;
  2871. info->lvds_pwr_off_seq_blon_to_vary_bl_in_4ms =
  2872. info_v8->ucLVDSPwrOffSeqBLONtoVARY_BL_in4Ms;
  2873. info->lvds_off_to_on_delay_in_4ms =
  2874. info_v8->ucLVDSOffToOnDelay_in4Ms;
  2875. info->lvds_bit_depth_control_val =
  2876. le32_to_cpu(info_v8->ulLCDBitDepthControlVal);
  2877. for (i = 0; i < NUMBER_OF_AVAILABLE_SCLK; ++i) {
  2878. /* Convert [10KHz] into [KHz] */
  2879. info->avail_s_clk[i].supported_s_clk =
  2880. le32_to_cpu(info_v8->sAvail_SCLK[i].ulSupportedSCLK) * 10;
  2881. info->avail_s_clk[i].voltage_index =
  2882. le16_to_cpu(info_v8->sAvail_SCLK[i].usVoltageIndex);
  2883. info->avail_s_clk[i].voltage_id =
  2884. le16_to_cpu(info_v8->sAvail_SCLK[i].usVoltageID);
  2885. }
  2886. for (i = 0; i < NUMBER_OF_UCHAR_FOR_GUID; ++i) {
  2887. info->ext_disp_conn_info.gu_id[i] =
  2888. info_v8->sExtDispConnInfo.ucGuid[i];
  2889. }
  2890. for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; ++i) {
  2891. info->ext_disp_conn_info.path[i].device_connector_id =
  2892. object_id_from_bios_object_id(
  2893. le16_to_cpu(info_v8->sExtDispConnInfo.sPath[i].usDeviceConnector));
  2894. info->ext_disp_conn_info.path[i].ext_encoder_obj_id =
  2895. object_id_from_bios_object_id(
  2896. le16_to_cpu(info_v8->sExtDispConnInfo.sPath[i].usExtEncoderObjId));
  2897. info->ext_disp_conn_info.path[i].device_tag =
  2898. le16_to_cpu(info_v8->sExtDispConnInfo.sPath[i].usDeviceTag);
  2899. info->ext_disp_conn_info.path[i].device_acpi_enum =
  2900. le16_to_cpu(info_v8->sExtDispConnInfo.sPath[i].usDeviceACPIEnum);
  2901. info->ext_disp_conn_info.path[i].ext_aux_ddc_lut_index =
  2902. info_v8->sExtDispConnInfo.sPath[i].ucExtAUXDDCLutIndex;
  2903. info->ext_disp_conn_info.path[i].ext_hpd_pin_lut_index =
  2904. info_v8->sExtDispConnInfo.sPath[i].ucExtHPDPINLutIndex;
  2905. info->ext_disp_conn_info.path[i].channel_mapping.raw =
  2906. info_v8->sExtDispConnInfo.sPath[i].ucChannelMapping;
  2907. }
  2908. info->ext_disp_conn_info.checksum =
  2909. info_v8->sExtDispConnInfo.ucChecksum;
  2910. return BP_RESULT_OK;
  2911. }
  2912. /*
  2913. * get_integrated_info_v8
  2914. *
  2915. * @brief
  2916. * Get V8 integrated BIOS information
  2917. *
  2918. * @param
  2919. * bios_parser *bp - [in]BIOS parser handler to get master data table
  2920. * integrated_info *info - [out] store and output integrated info
  2921. *
  2922. * @return
  2923. * enum bp_result - BP_RESULT_OK if information is available,
  2924. * BP_RESULT_BADBIOSTABLE otherwise.
  2925. */
  2926. static enum bp_result get_integrated_info_v9(
  2927. struct bios_parser *bp,
  2928. struct integrated_info *info)
  2929. {
  2930. ATOM_INTEGRATED_SYSTEM_INFO_V1_9 *info_v9;
  2931. uint32_t i;
  2932. info_v9 = GET_IMAGE(ATOM_INTEGRATED_SYSTEM_INFO_V1_9,
  2933. bp->master_data_tbl->ListOfDataTables.IntegratedSystemInfo);
  2934. if (!info_v9)
  2935. return BP_RESULT_BADBIOSTABLE;
  2936. info->boot_up_engine_clock = le32_to_cpu(info_v9->ulBootUpEngineClock) * 10;
  2937. info->dentist_vco_freq = le32_to_cpu(info_v9->ulDentistVCOFreq) * 10;
  2938. info->boot_up_uma_clock = le32_to_cpu(info_v9->ulBootUpUMAClock) * 10;
  2939. for (i = 0; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
  2940. /* Convert [10KHz] into [KHz] */
  2941. info->disp_clk_voltage[i].max_supported_clk =
  2942. le32_to_cpu(info_v9->sDISPCLK_Voltage[i].ulMaximumSupportedCLK) * 10;
  2943. info->disp_clk_voltage[i].voltage_index =
  2944. le32_to_cpu(info_v9->sDISPCLK_Voltage[i].ulVoltageIndex);
  2945. }
  2946. info->boot_up_req_display_vector =
  2947. le32_to_cpu(info_v9->ulBootUpReqDisplayVector);
  2948. info->gpu_cap_info = le32_to_cpu(info_v9->ulGPUCapInfo);
  2949. /*
  2950. * system_config: Bit[0] = 0 : PCIE power gating disabled
  2951. * = 1 : PCIE power gating enabled
  2952. * Bit[1] = 0 : DDR-PLL shut down disabled
  2953. * = 1 : DDR-PLL shut down enabled
  2954. * Bit[2] = 0 : DDR-PLL power down disabled
  2955. * = 1 : DDR-PLL power down enabled
  2956. */
  2957. info->system_config = le32_to_cpu(info_v9->ulSystemConfig);
  2958. info->cpu_cap_info = le32_to_cpu(info_v9->ulCPUCapInfo);
  2959. info->boot_up_nb_voltage = le16_to_cpu(info_v9->usBootUpNBVoltage);
  2960. info->ext_disp_conn_info_offset = le16_to_cpu(info_v9->usExtDispConnInfoOffset);
  2961. info->memory_type = info_v9->ucMemoryType;
  2962. info->ma_channel_number = info_v9->ucUMAChannelNumber;
  2963. info->gmc_restore_reset_time = le32_to_cpu(info_v9->ulGMCRestoreResetTime);
  2964. info->minimum_n_clk = le32_to_cpu(info_v9->ulNbpStateNClkFreq[0]);
  2965. for (i = 1; i < 4; ++i)
  2966. info->minimum_n_clk =
  2967. info->minimum_n_clk < le32_to_cpu(info_v9->ulNbpStateNClkFreq[i]) ?
  2968. info->minimum_n_clk : le32_to_cpu(info_v9->ulNbpStateNClkFreq[i]);
  2969. info->idle_n_clk = le32_to_cpu(info_v9->ulIdleNClk);
  2970. info->ddr_dll_power_up_time = le32_to_cpu(info_v9->ulDDR_DLL_PowerUpTime);
  2971. info->ddr_pll_power_up_time = le32_to_cpu(info_v9->ulDDR_PLL_PowerUpTime);
  2972. info->pcie_clk_ss_type = le16_to_cpu(info_v9->usPCIEClkSSType);
  2973. info->lvds_ss_percentage = le16_to_cpu(info_v9->usLvdsSSPercentage);
  2974. info->lvds_sspread_rate_in_10hz = le16_to_cpu(info_v9->usLvdsSSpreadRateIn10Hz);
  2975. info->hdmi_ss_percentage = le16_to_cpu(info_v9->usHDMISSPercentage);
  2976. info->hdmi_sspread_rate_in_10hz = le16_to_cpu(info_v9->usHDMISSpreadRateIn10Hz);
  2977. info->dvi_ss_percentage = le16_to_cpu(info_v9->usDVISSPercentage);
  2978. info->dvi_sspread_rate_in_10_hz = le16_to_cpu(info_v9->usDVISSpreadRateIn10Hz);
  2979. info->max_lvds_pclk_freq_in_single_link =
  2980. le16_to_cpu(info_v9->usMaxLVDSPclkFreqInSingleLink);
  2981. info->lvds_misc = info_v9->ucLvdsMisc;
  2982. info->lvds_pwr_on_seq_dig_on_to_de_in_4ms =
  2983. info_v9->ucLVDSPwrOnSeqDIGONtoDE_in4Ms;
  2984. info->lvds_pwr_on_seq_de_to_vary_bl_in_4ms =
  2985. info_v9->ucLVDSPwrOnSeqDEtoVARY_BL_in4Ms;
  2986. info->lvds_pwr_on_seq_vary_bl_to_blon_in_4ms =
  2987. info_v9->ucLVDSPwrOnSeqVARY_BLtoBLON_in4Ms;
  2988. info->lvds_pwr_off_seq_vary_bl_to_de_in4ms =
  2989. info_v9->ucLVDSPwrOffSeqVARY_BLtoDE_in4Ms;
  2990. info->lvds_pwr_off_seq_de_to_dig_on_in4ms =
  2991. info_v9->ucLVDSPwrOffSeqDEtoDIGON_in4Ms;
  2992. info->lvds_pwr_off_seq_blon_to_vary_bl_in_4ms =
  2993. info_v9->ucLVDSPwrOffSeqBLONtoVARY_BL_in4Ms;
  2994. info->lvds_off_to_on_delay_in_4ms =
  2995. info_v9->ucLVDSOffToOnDelay_in4Ms;
  2996. info->lvds_bit_depth_control_val =
  2997. le32_to_cpu(info_v9->ulLCDBitDepthControlVal);
  2998. for (i = 0; i < NUMBER_OF_AVAILABLE_SCLK; ++i) {
  2999. /* Convert [10KHz] into [KHz] */
  3000. info->avail_s_clk[i].supported_s_clk =
  3001. le32_to_cpu(info_v9->sAvail_SCLK[i].ulSupportedSCLK) * 10;
  3002. info->avail_s_clk[i].voltage_index =
  3003. le16_to_cpu(info_v9->sAvail_SCLK[i].usVoltageIndex);
  3004. info->avail_s_clk[i].voltage_id =
  3005. le16_to_cpu(info_v9->sAvail_SCLK[i].usVoltageID);
  3006. }
  3007. for (i = 0; i < NUMBER_OF_UCHAR_FOR_GUID; ++i) {
  3008. info->ext_disp_conn_info.gu_id[i] =
  3009. info_v9->sExtDispConnInfo.ucGuid[i];
  3010. }
  3011. for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; ++i) {
  3012. info->ext_disp_conn_info.path[i].device_connector_id =
  3013. object_id_from_bios_object_id(
  3014. le16_to_cpu(info_v9->sExtDispConnInfo.sPath[i].usDeviceConnector));
  3015. info->ext_disp_conn_info.path[i].ext_encoder_obj_id =
  3016. object_id_from_bios_object_id(
  3017. le16_to_cpu(info_v9->sExtDispConnInfo.sPath[i].usExtEncoderObjId));
  3018. info->ext_disp_conn_info.path[i].device_tag =
  3019. le16_to_cpu(info_v9->sExtDispConnInfo.sPath[i].usDeviceTag);
  3020. info->ext_disp_conn_info.path[i].device_acpi_enum =
  3021. le16_to_cpu(info_v9->sExtDispConnInfo.sPath[i].usDeviceACPIEnum);
  3022. info->ext_disp_conn_info.path[i].ext_aux_ddc_lut_index =
  3023. info_v9->sExtDispConnInfo.sPath[i].ucExtAUXDDCLutIndex;
  3024. info->ext_disp_conn_info.path[i].ext_hpd_pin_lut_index =
  3025. info_v9->sExtDispConnInfo.sPath[i].ucExtHPDPINLutIndex;
  3026. info->ext_disp_conn_info.path[i].channel_mapping.raw =
  3027. info_v9->sExtDispConnInfo.sPath[i].ucChannelMapping;
  3028. }
  3029. info->ext_disp_conn_info.checksum =
  3030. info_v9->sExtDispConnInfo.ucChecksum;
  3031. return BP_RESULT_OK;
  3032. }
  3033. /*
  3034. * construct_integrated_info
  3035. *
  3036. * @brief
  3037. * Get integrated BIOS information based on table revision
  3038. *
  3039. * @param
  3040. * bios_parser *bp - [in]BIOS parser handler to get master data table
  3041. * integrated_info *info - [out] store and output integrated info
  3042. *
  3043. * @return
  3044. * enum bp_result - BP_RESULT_OK if information is available,
  3045. * BP_RESULT_BADBIOSTABLE otherwise.
  3046. */
  3047. static enum bp_result construct_integrated_info(
  3048. struct bios_parser *bp,
  3049. struct integrated_info *info)
  3050. {
  3051. enum bp_result result = BP_RESULT_BADBIOSTABLE;
  3052. ATOM_COMMON_TABLE_HEADER *header;
  3053. struct atom_data_revision revision;
  3054. if (bp->master_data_tbl->ListOfDataTables.IntegratedSystemInfo) {
  3055. header = GET_IMAGE(ATOM_COMMON_TABLE_HEADER,
  3056. bp->master_data_tbl->ListOfDataTables.IntegratedSystemInfo);
  3057. get_atom_data_table_revision(header, &revision);
  3058. /* Don't need to check major revision as they are all 1 */
  3059. switch (revision.minor) {
  3060. case 8:
  3061. result = get_integrated_info_v8(bp, info);
  3062. break;
  3063. case 9:
  3064. result = get_integrated_info_v9(bp, info);
  3065. break;
  3066. default:
  3067. return result;
  3068. }
  3069. }
  3070. /* Sort voltage table from low to high*/
  3071. if (result == BP_RESULT_OK) {
  3072. struct clock_voltage_caps temp = {0, 0};
  3073. uint32_t i;
  3074. uint32_t j;
  3075. for (i = 1; i < NUMBER_OF_DISP_CLK_VOLTAGE; ++i) {
  3076. for (j = i; j > 0; --j) {
  3077. if (
  3078. info->disp_clk_voltage[j].max_supported_clk <
  3079. info->disp_clk_voltage[j-1].max_supported_clk) {
  3080. /* swap j and j - 1*/
  3081. temp = info->disp_clk_voltage[j-1];
  3082. info->disp_clk_voltage[j-1] =
  3083. info->disp_clk_voltage[j];
  3084. info->disp_clk_voltage[j] = temp;
  3085. }
  3086. }
  3087. }
  3088. }
  3089. return result;
  3090. }
  3091. static struct integrated_info *bios_parser_create_integrated_info(
  3092. struct dc_bios *dcb)
  3093. {
  3094. struct bios_parser *bp = BP_FROM_DCB(dcb);
  3095. struct integrated_info *info = NULL;
  3096. info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);
  3097. if (info == NULL) {
  3098. ASSERT_CRITICAL(0);
  3099. return NULL;
  3100. }
  3101. if (construct_integrated_info(bp, info) == BP_RESULT_OK)
  3102. return info;
  3103. kfree(info);
  3104. return NULL;
  3105. }
  3106. /******************************************************************************/
  3107. static const struct dc_vbios_funcs vbios_funcs = {
  3108. .get_connectors_number = bios_parser_get_connectors_number,
  3109. .get_encoder_id = bios_parser_get_encoder_id,
  3110. .get_connector_id = bios_parser_get_connector_id,
  3111. .get_dst_number = bios_parser_get_dst_number,
  3112. .get_src_obj = bios_parser_get_src_obj,
  3113. .get_dst_obj = bios_parser_get_dst_obj,
  3114. .get_i2c_info = bios_parser_get_i2c_info,
  3115. .get_voltage_ddc_info = bios_parser_get_voltage_ddc_info,
  3116. .get_thermal_ddc_info = bios_parser_get_thermal_ddc_info,
  3117. .get_hpd_info = bios_parser_get_hpd_info,
  3118. .get_device_tag = bios_parser_get_device_tag,
  3119. .get_firmware_info = bios_parser_get_firmware_info,
  3120. .get_spread_spectrum_info = bios_parser_get_spread_spectrum_info,
  3121. .get_ss_entry_number = bios_parser_get_ss_entry_number,
  3122. .get_embedded_panel_info = bios_parser_get_embedded_panel_info,
  3123. .get_gpio_pin_info = bios_parser_get_gpio_pin_info,
  3124. .get_embedded_panel_info = bios_parser_get_embedded_panel_info,
  3125. .get_gpio_pin_info = bios_parser_get_gpio_pin_info,
  3126. .get_encoder_cap_info = bios_parser_get_encoder_cap_info,
  3127. /* bios scratch register communication */
  3128. .is_accelerated_mode = bios_is_accelerated_mode,
  3129. .set_scratch_critical_state = bios_parser_set_scratch_critical_state,
  3130. .is_device_id_supported = bios_parser_is_device_id_supported,
  3131. /* COMMANDS */
  3132. .encoder_control = bios_parser_encoder_control,
  3133. .transmitter_control = bios_parser_transmitter_control,
  3134. .crt_control = bios_parser_crt_control, /* not used in DAL3. keep for now in case we need to support VGA on Bonaire */
  3135. .enable_crtc = bios_parser_enable_crtc,
  3136. .adjust_pixel_clock = bios_parser_adjust_pixel_clock,
  3137. .set_pixel_clock = bios_parser_set_pixel_clock,
  3138. .set_dce_clock = bios_parser_set_dce_clock,
  3139. .enable_spread_spectrum_on_ppll = bios_parser_enable_spread_spectrum_on_ppll,
  3140. .program_crtc_timing = bios_parser_program_crtc_timing, /* still use. should probably retire and program directly */
  3141. .crtc_source_select = bios_parser_crtc_source_select, /* still use. should probably retire and program directly */
  3142. .program_display_engine_pll = bios_parser_program_display_engine_pll,
  3143. .enable_disp_power_gating = bios_parser_enable_disp_power_gating,
  3144. /* SW init and patch */
  3145. .post_init = bios_parser_post_init, /* patch vbios table for mxm module by reading i2c */
  3146. .bios_parser_destroy = bios_parser_destroy,
  3147. };
  3148. static bool bios_parser_construct(
  3149. struct bios_parser *bp,
  3150. struct bp_init_data *init,
  3151. enum dce_version dce_version)
  3152. {
  3153. uint16_t *rom_header_offset = NULL;
  3154. ATOM_ROM_HEADER *rom_header = NULL;
  3155. ATOM_OBJECT_HEADER *object_info_tbl;
  3156. struct atom_data_revision tbl_rev = {0};
  3157. if (!init)
  3158. return false;
  3159. if (!init->bios)
  3160. return false;
  3161. bp->base.funcs = &vbios_funcs;
  3162. bp->base.bios = init->bios;
  3163. bp->base.bios_size = bp->base.bios[BIOS_IMAGE_SIZE_OFFSET] * BIOS_IMAGE_SIZE_UNIT;
  3164. bp->base.ctx = init->ctx;
  3165. bp->base.bios_local_image = NULL;
  3166. rom_header_offset =
  3167. GET_IMAGE(uint16_t, OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER);
  3168. if (!rom_header_offset)
  3169. return false;
  3170. rom_header = GET_IMAGE(ATOM_ROM_HEADER, *rom_header_offset);
  3171. if (!rom_header)
  3172. return false;
  3173. get_atom_data_table_revision(&rom_header->sHeader, &tbl_rev);
  3174. if (tbl_rev.major >= 2 && tbl_rev.minor >= 2)
  3175. return false;
  3176. bp->master_data_tbl =
  3177. GET_IMAGE(ATOM_MASTER_DATA_TABLE,
  3178. rom_header->usMasterDataTableOffset);
  3179. if (!bp->master_data_tbl)
  3180. return false;
  3181. bp->object_info_tbl_offset = DATA_TABLES(Object_Header);
  3182. if (!bp->object_info_tbl_offset)
  3183. return false;
  3184. object_info_tbl =
  3185. GET_IMAGE(ATOM_OBJECT_HEADER, bp->object_info_tbl_offset);
  3186. if (!object_info_tbl)
  3187. return false;
  3188. get_atom_data_table_revision(&object_info_tbl->sHeader,
  3189. &bp->object_info_tbl.revision);
  3190. if (bp->object_info_tbl.revision.major == 1
  3191. && bp->object_info_tbl.revision.minor >= 3) {
  3192. ATOM_OBJECT_HEADER_V3 *tbl_v3;
  3193. tbl_v3 = GET_IMAGE(ATOM_OBJECT_HEADER_V3,
  3194. bp->object_info_tbl_offset);
  3195. if (!tbl_v3)
  3196. return false;
  3197. bp->object_info_tbl.v1_3 = tbl_v3;
  3198. } else if (bp->object_info_tbl.revision.major == 1
  3199. && bp->object_info_tbl.revision.minor >= 1)
  3200. bp->object_info_tbl.v1_1 = object_info_tbl;
  3201. else
  3202. return false;
  3203. dal_bios_parser_init_cmd_tbl(bp);
  3204. dal_bios_parser_init_cmd_tbl_helper(&bp->cmd_helper, dce_version);
  3205. bp->base.integrated_info = bios_parser_create_integrated_info(&bp->base);
  3206. return true;
  3207. }
  3208. /******************************************************************************/