bios_parser.c 110 KB

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