bios_parser.c 109 KB

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